I'm using the code below to modify both my NewForm and my EditForm in SharePoint 2007. The script dynamically hides/shows fields based on a selected drop-down. The problem is with my EditForm the drop-down is already selected, but the fields remain hidden because the script is waiting for the field to change. So when someone creates a new item and selects "Project" from the "Type" drop-down, the "Project Name" field will display, which is working fine and dandy. But on the EditForm, if that field has already been filled-in it should display, otherwise if the "Type" field is not "Project" the "Project Name" field should remain hidden. But I have to re-select the "Project" option for the field to show. I've tried modifying the code from onchange to onload and a number of other handlers, but nothing seems to be working. Any help is appreciated.
_spBodyOnLoadFunctionNames.push("hideFieldsOnStart"); function hideFieldsOnStart() { var hiddenField = getTagFromIdentifierAndTitle("input","TextField","Project Name"); hiddenField.parentNode.parentNode.parentNode.style.display="none"; getTagFromIdentifiera=AndTitle("select","DropDownChoice","Type").onchange = function() {ChangeEvent()}; } function ChangeEvent(){ var dropDown = getTagFromIdentifierAndTitle("select"DropDownChoice","Type"); var option = dropDown.options[dropDown.selectedIndex].text; var hiddenField = getTagFromIdentifierAndTitle("input","TextField","Project Name"); if (option == "Project"){ hiddenField.parentNode.parentNode.parentNode.style.display=""; } else{ hiddenField.parentNode.parentNode.parentNode.style.display="none"; } } function getTagFromIdentifierAndTitle(tagName, identifier, title){ var len = identifier.length; var tags = document.getElementsByTagName(tagName); for (var i=0; i < tags.length; i++) { var tempString = tags[i].id; if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) { return tags[i]; } } return null; }