Newby Javascript question here. Oh and I know there heaps of different ways to do this—a lot of which are explained on this site—but this question relates specifically to this bit of code.
<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 code has been used extensively on the site that I’m working on [it’s a sharepoint page that has some custom javascript], but if I use it on a new page I keep getting an error for getField('tr', 'TRA').style.display = 'none' style is undefined or not an object.
Am I getting a comma in the wrong place or is the sharepoint page calling the getElementsByTagName somewhere else that I’m not?
Any help troubleshooting this specific bit of code would greatly be appreciated.
Regards
Your
SetHidden()function may get called before the page is fully loaded. Try changing it to: