Hiding Table Rows

L

luvdairish

Can someone please look at my code and see why tables are not hiding
properly?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Untitled Document</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<SCRIPT type=text/javascript>


<!--//
function hideRows(){

for (i = 0; i <= 5; i++){
id = ('table'+i);
document.write(id);
var e2 = document.getElementById(id);
document.write("<br>"+e2);
e2.style.display='none';
document.write("<br>"+i);
}


}
//-->
</SCRIPT>

</HEAD>

<BODY onload="hideRows()" >

<FORM name=form1 action="" method=post>
<TABLE width="75%" border=0>
<TBODY>
<TR>
<TD width="6%"><INPUT onclick="hideShow('table1')" type=checkbox
value=1 name=check_1></TD>
<TD width="94%">All hardware and software is listed</TD></TR>
<TR>
<TD>&nbsp;</TD>
<TD>
<TABLE id=table1 borderColor=#ff0000 cellSpacing=0 cellPadding=0
width="40%" border=0>
<TBODY>
<TR>
<TD><INPUT type=radio value=checkbox name=radio> Issue</TD>
<TD><INPUT type=radio value=checkbox name=radio> Minor
Issue</TD>
<TD><INPUT type=radio value=checkbox name=radio> Ok</TD>
</TR>
<TR>
<TD align=middle colSpan=3><INPUT size=50></TD>
</TR>
<TR>
<TD>&nbsp</TD>
</TR>
</TBODY>
</TABLE>
</TD></TR>
<TR>
<TD width="6%"><INPUT onclick="hideShow('table2')" type=checkbox
value=1 name=check_2></TD>
<TD width="94%">ID number matches manufacturer's request and chip
label</TD>
</TR>
<TR>
<TD>&nbsp;</TD>
<TD>
<DIV align=left></DIV>
<TABLE id=table2 borderColor=#ff0000 cellSpacing=0 cellPadding=0
width="40%" border=0>
<TBODY>
<TR>
<TD><INPUT type=radio value=checkbox name=radio2>
Issue</TD>
<TD><INPUT type=radio value=checkbox name=radio2> Minor
Issue</TD>
<TD><INPUT type=radio value=checkbox name=radio2> Ok</TD>
</TR>
<TR>
<TD align=middle colSpan=3><INPUT size=50></TD>
</TR>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
<TR>
<TD>&nbsp;</TD>
<TD>&nbsp;</TD></TR></TBODY></TABLE>
<P>&nbsp;</P></FORM></BODY></HTML>



THANKS!!!!!
 
J

Joakim Braun

Can someone please look at my code and see why tables are not hiding
properly?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Untitled Document</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<SCRIPT type=text/javascript>


<!--//
function hideRows(){

for (i = 0; i <= 5; i++){

In your code you have table1 and table2, not table0, table3, table4 or
table5. The code will start executing by generating the id "table0".
id = ('table'+i);

id (by default declared as a global) probably goes out of scope after the
loop, but to avoid confusing bugs, always create local variables:
var id = ('table'+i);
document.write(id);

In theory, you have now overwritten your document contents, including the
tables. Practical browser results will vary. Don't try to append stuff to
existing document contents using document.write.
var e2 = document.getElementById(id);

First time loop executes, you will have failed to get an element with the id
document.write("<br>"+e2);

What's that supposed to do? Disregarding the fact that you'll have a null
object reference (because you tried to access "table0", which doesn't
exist) - you are trying to turn an object reference into HTML, then write it
to the document, obliterating the supposedly existing object?
e2.style.display='none';
document.write("<br>"+i);

The code has probably errored out before this because of the null object
reference.

Try this loop:

for(/*code here to correctly loop through object identifiers with the loop
variable i*/){

var id = "table" + i;
var theRow = document.getElementById(id);
if(theRow)
theRow.style.display = "none";
}

}

}
//-->
</SCRIPT>
</HEAD>

<BODY onload="hideRows()" >

<FORM name=form1 action="" method=post>
<TABLE width="75%" border=0>
<TBODY>
<TR>
<TD width="6%"><INPUT onclick="hideShow('table1')" type=checkbox
value=1 name=check_1></TD>
<TD width="94%">All hardware and software is listed</TD></TR>
<TR>
<TD>&nbsp;</TD>
<TD>
<TABLE id=table1 borderColor=#ff0000 cellSpacing=0 cellPadding=0
width="40%" border=0>
<TBODY>
<TR>
<TD><INPUT type=radio value=checkbox name=radio> Issue</TD>
<TD><INPUT type=radio value=checkbox name=radio> Minor
Issue</TD>
<TD><INPUT type=radio value=checkbox name=radio> Ok</TD>
</TR>
<TR>
<TD align=middle colSpan=3><INPUT size=50></TD>
</TR>
<TR>
<TD>&nbsp</TD>
</TR>
</TBODY>
</TABLE>
</TD></TR>
<TR>
<TD width="6%"><INPUT onclick="hideShow('table2')" type=checkbox
value=1 name=check_2></TD>
<TD width="94%">ID number matches manufacturer's request and chip
label</TD>
</TR>
<TR>
<TD>&nbsp;</TD>
<TD>
<DIV align=left></DIV>
<TABLE id=table2 borderColor=#ff0000 cellSpacing=0 cellPadding=0
width="40%" border=0>
<TBODY>
<TR>
<TD><INPUT type=radio value=checkbox name=radio2>
Issue</TD>
<TD><INPUT type=radio value=checkbox name=radio2> Minor
Issue</TD>
<TD><INPUT type=radio value=checkbox name=radio2> Ok</TD>
</TR>
<TR>
<TD align=middle colSpan=3><INPUT size=50></TD>
</TR>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
<TR>
<TD>&nbsp;</TD>
<TD>&nbsp;</TD></TR></TBODY></TABLE>
<P>&nbsp;</P></FORM></BODY></HTML>

Joakim Braun
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top