...

View Full Version : A small problem in javascript



xaverian
06-26-2012, 12:23 PM
Hi ,

I have the following small javascript embedded in the html. Please notice there is a drop-down filter in the "Status" column. If I select it as "valid" then all the rows having "OK" status should be returned. But instead of returing two rows it is returning only one row and ignoring the other. Can anybody please point me out what is going wrong ?

Thanks in advance.


<html>
<head>
<title>Collections</title>
</head>
<body bgcolor="#FFFFFF">
<TABLE BORDER=1 id="maintab" ><TR BGCOLOR="#D0D0D0">
<TH ALIGN=LEFT>Task</TH><TH ALIGN=LEFT>Command</TH><TH ALIGN=LEFT>Method</TH><TH
ALIGN=LEFT>Status<BR>


<select onchange="showRows(this.value)">
<option value="all">show status</option>
<option value="all">all</option>
<option value="active">valid</option>
</select>


</TH><TH ALIGN=LEFT>Task version</TH><TH ALIGN=LEFT>Tool version</TH><TH
ALIGN=LEFT>Last changed</TH><TH ALIGN=LEFT>Comments</TH></TR>

<script type="text/javascript">
mytab=document.getElementById("maintab")
function showRows(val){
for (var i = 0; i < mytab.rows.length; i++) {
if (val=="all"){
mytab.rows[i].style.display="table-row"
} else {
if (mytab.rows[i].innerHTML.match("-")){
mytab.rows[i].style.display="none"
}
} //else blk end
}
} ;

</script>


<TR><TD rowspan=1><A HREF="method.pl?path=/home/max/;task=drc;command=create">drc</A></TD><TD rowspan=1><A HREF="file:///home/max/xyzdev_tech_demo_1/xyx_HTML/web_drc_create.html">create</TD><TD NOWRAP>drc</TD><TD NOWRAP><FONT COLOR="green">OK</FONT></TD><TD NOWRAP>v1.2</TD><TD NOWRAP>2005r02-iw</TD><TD NOWRAP>Wed Jul 11 2007 16:29:52</TD><TD NOWRAP>&nbsp;</TD></TR>
<TR><TD rowspan=1><A HREF="method.pl?path=/home/max/;task=gds;command=create">gds</A></TD><TD rowspan=1><A HREF="file:///home/max/xyzdev_tech_demo_1/xyx_HTML/web_gds_create.html">create</TD><TD NOWRAP>gds</TD><TD NOWRAP><FONT COLOR="green">OK</FONT></TD><TD NOWRAP>v1.2</TD><TD NOWRAP>undef/INF: undef</TD><TD NOWRAP>Wed Jul 11 2007 16:28:51</TD><TD NOWRAP>&nbsp;</TD></TR>
<TR><TD rowspan=1><A HREF="method.pl?path=/home/max/;task=task_template;command=create">task_template</A></TD><TD rowspan=1>create</TD><TD NOWRAP>&nbsp;</TD><TD NOWRAP>-</TD><TD NOWRAP>&nbsp;</TD><TD NOWRAP>&nbsp;</TD><TD NOWRAP>&nbsp;</TD><TD NOWRAP>&nbsp;</TD></TR>
</TABLE>
<p /><br />
</body>
</html>

DaveyErwin
06-26-2012, 02:30 PM
you are comparing the whole row
when you should compare only
the cell ...


<!doctype html>
<html>
<head>
<title>Collections</title>
</head>
<body bgcolor="#FFFFFF">
<TABLE BORDER=1 id="maintab" >
<TR BGCOLOR="#D0D0D0">
<TH ALIGN=LEFT>Task</TH>
<TH ALIGN=LEFT>Command</TH>
<TH ALIGN=LEFT>Method</TH>
<TH ALIGN=LEFT>Status<BR>
<select onchange="showRows(this.value)">
<option value="all">show status</option>
<option value="all">all</option>
<option value="active">valid</option>
</select></TH>
<TH ALIGN=LEFT>Task version</TH>
<TH ALIGN=LEFT>Tool version</TH>
<TH ALIGN=LEFT>Last changed</TH>
<TH ALIGN=LEFT>Comments</TH>
</TR>
<TR>
<TD rowspan=1><A HREF="method.pl?path=/home/max/;task=drc;command=create">drc</A></TD>
<TD rowspan=1><A HREF="file:///home/max/xyzdev_tech_demo_1/xyx_HTML/web_drc_create.html">create</TD>
<TD NOWRAP>drc</TD>
<TD NOWRAP><FONT COLOR="green">OK</FONT></TD>
<TD NOWRAP>v1.2</TD>
<TD NOWRAP>2005r02-iw</TD>
<TD NOWRAP>Wed Jul 11 2007 16:29:52</TD>
<TD NOWRAP>&nbsp;</TD>
</TR>
<TR>
<TD rowspan=1><A HREF="method.pl?path=/home/max/;task=gds;command=create">gds</A></TD>
<TD rowspan=1><A HREF="file:///home/max/xyzdev_tech_demo_1/xyx_HTML/web_gds_create.html">create</TD>
<TD NOWRAP>gds</TD>
<TD NOWRAP><FONT COLOR="green">OK</FONT></TD>
<TD NOWRAP>v1.2</TD>
<TD NOWRAP>undef/INF: undef</TD>
<TD NOWRAP>Wed Jul 11 2007 16:28:51</TD>
<TD NOWRAP>&nbsp;</TD>
</TR>
<TR>
<TD rowspan=1><A HREF="method.pl?path=/home/max/;task=task_template;command=create">task_template</A></TD>
<TD rowspan=1>create</TD>
<TD NOWRAP>&nbsp;</TD>
<TD NOWRAP>-</TD>
<TD NOWRAP>&nbsp;</TD>
<TD NOWRAP>&nbsp;</TD>
<TD NOWRAP>&nbsp;</TD>
<TD NOWRAP>&nbsp;</TD>
</TR>
</TABLE>
<p /><br />

<script type="text/javascript">
mytab=document.getElementById("maintab")
function showRows(val){
for (var i = 0; i < mytab.rows.length; i++) {
if (val=="all"){
mytab.rows[i].style.display="table-row"
} else {
if (mytab.rows[i].cells[3].innerHTML.match("-")){
mytab.rows[i].style.display="none"
}
} //else blk end
}
} ;

</script>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum