Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    47
    Thanks
    3
    Thanked 0 Times in 0 Posts

    A small problem in javascript

    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.

    Code:
    <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>

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    970
    Thanks
    19
    Thanked 212 Times in 210 Posts
    you are comparing the whole row
    when you should compare only
    the cell ...

    Code:
    <!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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •