Click to See Complete Forum and Search --> : formfields in array


michelle
06-17-2003, 06:43 AM
<form id="myform">
<input type="text" name="stuff[0]">
<input type="text" name="stuff[1]">
</form>

How do I access the different values of this?

I have tried
document.myform.stuff[0].value;
but this only returns an error saying:
document.myform.stuff.0 is null

It seems to me that javascript can't cope with formfields in arrays?

Any thoughts?
// Michelle

SlankenOgen
06-17-2003, 06:54 AM
stuff[0] is a bad way to name the text fields as aName[0] is a means of accessing an array index.

You are probably confusing the browser.
Is is looking for an array element called stuff[0]

~mgb

michelle
06-17-2003, 07:07 AM
Is is looking for an array element called stuff[0]

Yes that's right, I thought this was the correct way of doing it, using javascript, but this seems to be it:

<form id="myform">
<input type="text" name="stuff">
<input type="text" name="stuff">
</form>

But when you post it and want access everything with PHP, you need to print out:
<form id="myform">
<input type="text" name="stuff[]">
<input type="text" name="stuff[]">
</form>

I think I mixed them up...

// Michelle