View Full Version : form field copying

Mar 19th, 2003, 05:47 AM

I have two form fields in a form named "myform".

One is:

<input type="text" name="thing[1]" value="Blaa">

and the other is:

<input type="text" name="stuff">

How do I copy the value of the first field into the second field.

I've tried the following:

document.myform.stuff.value = document.myform.thing[1].value;

But it gives the error:

Error: 'document.myform.thing.1' is null or not an object

The reason I need that "[1]" in the name of the first field is because I actually have many fields, all of them named "thing" but with different numbers (ie: thing[2], thing[3], etc...) This is so they get passed into my PHP script as an array.

Thanks for any help you can give,

Mar 19th, 2003, 07:21 AM
you can't use the dot syntax if the fieldname contains special characters. you can use the elements array instead.

document.myform.stuff.value = document.myform.elements["thing[1]"].value;

Mar 19th, 2003, 08:07 AM
That worked.