Question for Javascript beginners: I am aware that there are numerous ways to achieve this task, many of which are explained on various platforms. However, my question pertains specifically to the following code snippet.
<html>
<head>
<script type="text/javascript" language="javascript>
function getField(fieldType, fieldTitle) {
var docTags = document.getElementsByTagName(fieldType);
for (var i = 0; i < docTags.length; i++) {
if (docTags[i].title == fieldTitle) {
return docTags[i]
}
}
}
function SetHidden() {
getField('tr', 'TRA').style.display = 'none';
getField('tr', 'TRB').style.display = '';
}
SetHidden()
</script>
</head>
<body>
<table>
<tr title="TRA">
<td>Tier A Kit Count</td>
<tr title="TRB">
<td>Tier B Kit Count</td>
</tr>
</table>
</body>
</html>
This piece of code has been effectively utilized on a specific platform I work on (a customized SharePoint page with JavaScript). However, when attempting to implement it on a new page, I encounter an error regarding
getField('tr', 'TRA').style.display = 'none'
saying that style is undefined or not an object.
Could the error be due to a misplaced comma, or is there another location within the SharePoint page where getElementsByTagName is being called?
Any assistance with troubleshooting this particular code snippet would be highly appreciated.
Best regards