[Javascript] Add elements to form

Rees, Mark (TWIi London) mrees at twii.net
Mon Aug 6 11:34:20 CDT 2001


Hello

thanks for all the help, but I don't think I explained myself clearly
enough.

This is called in an "edit table" function (i.e. responds to an onclick
event after the whole page has loaded). So I have a table to which you can
for example add rows. Each cell has an individual form input containing its
value, formatting etc. What I was looking for was some way to do this
dynamically (since the cells are named with respect to their position in the
table, like row1column3 for example). So instead of having to write out
every time

<input type="hidden" name="R1C1" value="some text|bold">

I fancied document.form.R1C1.value='sometext|bold';

But it isn't having it. I presume this is because, as Hassan said, the form
elements collection is read only (presumably he means you can't create new
elements like this, because obviously you can change the value of existing
elements)?

Is that clearer?

Cheers

Mark

-----Original Message-----
From: Ben Curtis [mailto:Quixote at LaMancha.org]
Sent: 06 August 2001 17:08
To: javascript at latech.edu
Subject: Re: [Javascript] Add elements to form


>> <td id="1">Hello</td><input type="hidden name="1" value="Hello">
>> 
>> This seems a bit cumbersome. I've tried
>> 
>> document.formname.1.value='Hello';
>> 
>> Not surprisingly this doesn't work and I get  'document.formname.1 is
null
>> or not an object'.
...
> 
> Exactly when do you do this? The forms array is only initalized and
> accessible after the page has been loaded completely (onLoad, in other
> words).

I've never had it fail if I call the form object after the closing form tag,
if you don't want to wait for the onload to fire. If you try to refer to the
form object before the closing tag, you get the "not an object" error.

--
+Ben Curtis

Two guys walk into a bar.
The third guy ducks and goes around it.





_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
http://www.LaTech.edu/mailman/listinfo/javascript



More information about the Javascript mailing list