I am using a script to show and hide table rows based on selections from a drop down list. It works fine with only one drop down. When I add additional drop down menus, however, it shows the hidden rows, but it won't hide the previous selection. So you end up with everything being show at once unless you manually reset the list. I am using css display: none
to hide the table rows as the default state. The site I'm working on uses quirks mode. JQuery is not an option. I would really appreciate some help. I have to think the script could be tweaked so it will look at all the select lists. Thank you, and sorry for being such a noob.
Here's a fiddle: http://jsfiddle.net/matt_f/e58hk/
Here is the script:
function Cng(obj){
var opts=obj.options;
for (var z0=0;z0<opts.length;z0++){
if (document.getElementById(opts[z0].value)){
document.getElementById(opts[z0].value).style.display=opts[z0].selected?'table-row':'none';
}
}
}
Here is my html:
<select class=evidencemenu onchange="Cng(this);" >
<option value="" >Please select</option>
<!--USE THIS OPTION FOR TESTING -->
<option value="grade3art" >Grades 3-5 Art</option>
</select>
<select class=evidencemenu onchange="Cng(this);" >
<option value="" >Please select</option>
<!--USE THIS OPTION FOR TESTING -->
<option value="grade6ela" >Grades 6-8 ELA</option>
</select>
<select class=evidencemenu onchange="Cng(this);" >
<!--Do not use these for testing -->
<option value="" >Please select</option>
<option value="grade9ela" >Grades 9-12 ELA</option>
<option value="grade9math" >Grades 9-12 Math</option>
<option value="grade9art" >Grades 9-12 Art</option>
</select>
<TABLE width="960" border="1" cellspacing="0" cellpadding="5" summary="Domain 1, Indicator 1a">
<CAPTION>
This is the table caption. </CAPTION>
<TR>
<TH scope="col"> </TH>
<TH scope="col">Below Standard</TH>
<TH scope="col">Developing</TH>
<TH scope="col">Proficient</TH>
<TH scope="col">Exemplary</TH>
</TR>
<TR>
<TD><STRONG>asfghsdfgsd</STRONG></TD>
<TD> </TD>
<TD> </TD>
<TD> </TD>
<TD><EM>sdghsrthdfgbhdfgh</EM><EM></EM></TD>
</TR>
<TR>
<TD valign="top"><STRONG>sdfgsdfgsdf</STRONG></TD>
<TD valign="top">sdfghsdfg</TD>
<TD valign="top">sdfghdsfghfd</TD>
<TD valign="top"> dfghdfghf</TD>
<TD valign="top">sfghdfghdfghdfg</TD>
</TR>
<!--HERE IS THE FIRST HIDDEN ROW. IT IS SELECTED WITH THE FIRST DROP DOWN MENU. -->
<TR valign="top" class=hide ID=grade3art>
<TD><P><STRONG>Sample
Grades 3–5 hidden</STRONG></P>
<P><EM>adfgsdfgsdfgsdfgs</EM></P>
<P><EM>df</EM><EM>gs</EM><EM>dfgsd</EM></P></TD>
<TD><P><STRONG><EM>hidden text goes here</EM></STRONG></P></TD>
<TD><P><EM><STRONG>more hidden text goes here</STRONG></EM></P></TD>
<TD><p><strong><em>third column of hidden text</em></strong></p></TD>
<TD><p><strong><em>another column of hidden text</em></strong></p></TD>
</TR>
<TR>
<TD valign="top"><STRONG>asdfjahs dlkfj<SPAN class="super"></SPAN></STRONG></TD>
<TD valign="top">dafgsdfgsdfg</TD>
<TD valign="top">sdfgsdfgsdfg</TD>
<TD valign="top">sdfghsdfgsdfg</TD>
<TD valign="top">sdfsdfgsdfg</TD>
</TR>
<!--HERE IS THE SECOND HIDDEN ROW. THIS IS SELECTED WITH THE SECOND DROPDOWN MENU. -->
<TR class=hide id="grade6ela">
<TD valign="top"><P><STRONG>Sample </STRONG><STRONG>Grades 6-8 HIDDEN</STRONG></P></TD>
<TD valign="top">TEST TO ...</TD>
<TD valign="top">PRETEND THAT....</TD>
<TD valign="top">THIS IS..</TD>
<TD valign="top">GRADE 6 ELA HIDDEN TEXT</TD>
</TR>
<TR>
<TD valign="top"><STRONG>asfjal;skdjf</STRONG></TD>
<TD valign="top">sadlkjasl;dkfj</TD>
<TD valign="top">;salkdfjg sadl;fkgj</TD>
<TD valign="top">a;lksjdfa;lskdfja;ls</TD>
<TD valign="top">a;lskjfa;lskmnals;kd</TD>
</TR>
The css:
.hide {
display:none
}