Click to See Complete Forum and Search --> : Javascript Newbie!


robfromplymouth
01-21-2003, 03:47 AM
Hi everyone, I'm a relative newcomer to this but I do know some stuff! I'm trying to do something that looks really simple but I can't understand why it's not working. I want to get another <TR> to appear within a table when a link is clicked. I've scripted it out already but can't get it to work. Whenever I click the link, it blanks the page off rather than adding to the current table I am in. The code is below. Any ideas would be much appreciated. Thanks so much.

<HTML>
<BODY>
<TABLE>
<TR>
<TD>

<TABLE>
<TR>
<TD> Staff1 </TD>
<TD> Rob Bishop </TD>
</TR>
</TABLE>

</TD>
</TR>

<TR>
<TD>

<!-- <TABLE> <TR> <TD> Staff2 </TD> <TD> Tom Archer </TD> </TR> </TABLE> -->

<script language="Javascript">
var _checked=false;

function boxClicked()
{_checked = !_checked;
if (_checked)
{
var rt="<TABLE> <TR> <TD> Staff2 </TD> <TD> Tom Archer </TD> </TR> </TABLE>";
//alert(rt);
document.write(rt);
}
else
{
var rt="";
//alert(rt);
}
}

</script>

<a href="javascript:boxClicked()"> Add Another Staff Member </a>

</TD>
</TR>
</TABLE>
</BODY>
</HTML>

ivyshen
01-21-2003, 04:52 AM
your code should be working.

Check the following:

1. what browser version r u using? Is there any error msg?
2. insert the following msg box before the if statement to debug:
alert(_Checked)
3. Check is there anywhere else u could have changed the _Checked value?


finally document.write() is going to over write (not adding to) the current cell you've got on the page. is this intentional?

robfromplymouth
01-21-2003, 04:56 AM
Hiya, thanks for replying. My problem is that it IS overwriting. I need it to add the Tom Archer row to the current table underneath the Rob Bishop row. At the moment it just blanks the page out and writes the Tom Archer row to the (now empty) page.