Click to See Complete Forum and Search --> : object expected problem in simple script


baran
09-01-2003, 05:18 PM
this shouldn't be too hard for someone to solve. any help enormously appreciated. this little bug is causing me sleepless nights.

I have the javascript below. It is supposed to write a table in the second form on the page when the checkbox is clicked. but when I click the checkbox I get an 'object expected on line 5 Char 1' error. given how simple the form is I imagine its something an experienced programmer could spot easily...

here's the code:
<html>
<script type="text/javascript">
function writeclientdetailtable()
{
with (document.formTwo) {
writeln('<table cellspacing=15>');
writeln('<tr><td>File Number<BR><input type=textbox name="filenumber"></td>');
writeln('<td>First Name of Client<BR><input type=textbox name="clientonefirstname"></td>');
writeln('<td>Last Name of Client<BR><input type=textbox name="clientonelastname"></td>');
writeln('<tr><td>&nbsp;<BR><INPUT TYPE="submit" VALUE="Add New Record"></td>');
writeln('</TABLE>');
}
}
</script>

<form name="formOne">
<input type="submit" value="decoy">
</form>
<form name="formTwo">
Show client's details etc. <input type="checkbox" name="tickboxtoreplace" onClick="writeclientdetailtable(this.form)">
</form>
</html>


the form that is written by the function isn't complete yet but the code serves the purpose of illustrating my problem.

Thanks to anyone with any suggestions.

baran
09-01-2003, 05:19 PM
make that line 6 for the error.

baran
09-02-2003, 05:15 AM
Effectively what I want to do is to write some text into a form when a checkbox is clicked but without reloading the page.
an example which requires the page to be reloaded is here:
http://www.trans4mind.com/personal_development/JavaScript/docWrite3.htm
Is there a way to do this without reloading the page?

Fang
09-02-2003, 06:18 AM
You are attempting to write a new page.
Once your page has been loaded, a "writeln" will overwrite the existing contents.
Here is a simpler solution: Hide the table then use the onclick to show it. Note: input type="textbox" does not exist.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Show table</title>
</head>
<body>

<form name="formOne">
<input type="submit" value="decoy">
</form>
<form name="formTwo">
Show client's details etc. <input type="checkbox" name="tickboxtoreplace" onClick="document.getElementById('mytable').style.display='block';">
<table cellspacing="15" id="mytable" style="display:none;">
<tr><td>File Number<br><input type="text" name="filenumber"></td>
<td>First Name of Client<br><input type="text" name="clientonefirstname"></td>
<td>Last Name of Client<br><input type="text" name="clientonelastname"></td>
<tr><td> <br><input type="submit" value="Add New Record"></td>
</table>
</form>

</body>
</html>

baran
09-02-2003, 10:41 AM
Fang,

LORD HAVE MERCY!
I am sincerely impressed. neat, tidy and simple. many many thanks.:D