Hi All,
I am working on a MOSS 2007 platform. Here what i need to do is to show or hide columns based on drop down values. I am using the below code to implement, but not able to hide or show multiple fields. Please help me resolve the same.
<script type="text/javascript">_spBodyOnLoadFunctionNames.push("hideFieldsOnStart");
function hideFieldsOnStart() {
//hide the control at start
var control = getTagFromIdentifierAndTitle("input","TextField","hide textbox");
control.parentNode.parentNode.parentNode.style.display="none";
var control = getTagFromIdentifierAndTitle("input","TextField","Comments");
control.parentNode.parentNode.parentNode.style.display="none";
//control.parentNode.parentNode.parentNode.style.display="none";
//add an onchange event to the dropdown
getTagFromIdentifierAndTitle("select","DropDownChoice","selection").onchange = function() {ChangeEvent()};
}
function ChangeEvent()
{
//get the dropdown
var dropDown = getTagFromIdentifierAndTitle("select","DropDownChoice","selection");
//get the selected value
var option = dropDown.options[dropDown.selectedIndex].text;
//get the control
var control = getTagFromIdentifierAndTitle("input","TextField","hide textbox");
//show hide based on your condition
if(option == "yes")
{
control.parentNode.parentNode.parentNode.style.display="";
}
else if (option == "na")
{
control.parentNode.parentNode.parentNode.style.display="none";
}
else if (option == "no")
{
control.parentNode.parentNode.parentNode.style.display="none";
}}
//this gets the field based on title identifier and tagname
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;
}
</script>