Passing an Array to a form field

M

Mike

Hello,
I am trying to pass a js array ,Round1[],
to a form and send it. I can get it to work with serialized values but
I want to send the data as an array.
The arrays are filled with data. I am getting an error.

in the JS:
document.forms['aJaX'].Result1[].value = Round1[];
document.forms['aJaX'].Result2[].value = Round2[];
document.forms['aJaX'].Result3[].value = Round3[];
document.forms['aJaX'].Result4[].value = Round4[];
document.forms['aJaX'].Region.value = Region;
document.forms['aJaX'].submit();}

In The Form
<form name="aJaX" method="POST" action="saveteams.php"
style="position:absolute" >
<input type="hidden" name="Result1[]" value="" >
<input type="hidden" name="Result2[]" value="" >
<input type="hidden" name="Result3[]" value="" >
<input type="hidden" name="Result4[]" value="" >
<input type="hidden" name="Region" value="" >
</form>

Thanks
Mike
 
M

Martin Honnen

Mike said:
Hello,
I am trying to pass a js array ,Round1[],
to a form and send it. I can get it to work with serialized values but
I want to send the data as an array.
The arrays are filled with data. I am getting an error.

in the JS:
document.forms['aJaX'].Result1[].value = Round1[];
document.forms['aJaX'].Result2[].value = Round2[];
document.forms['aJaX'].Result3[].value = Round3[];
document.forms['aJaX'].Result4[].value = Round4[];
document.forms['aJaX'].Region.value = Region;
document.forms['aJaX'].submit();}

In The Form
<form name="aJaX" method="POST" action="saveteams.php"
style="position:absolute" >
<input type="hidden" name="Result1[]" value="" >

You are using the bracket notation at the wrong place.
document.forms['aJaX']
can be written as
document.forms.aJaX
but
document.forms['aJaX'].Result2[]
is not possible, there you need bracket notation, either
document.forms['aJaX']['Result2[]']
or
document.forms['aJaX'].elements['Result2[]']

And those right hand sides like
document.forms['aJaX'].Result2[].value = Round2[];
are also not syntactically correct, if the variable name is Round2 then
you need
document.forms['aJaX'].elements['Result2[]'] = Round2;
or as you say that is an array and you want to assign it as the form
control value you might want
document.forms['aJaX'].elements['Result2[]'] = Round2.join(',');
 
S

SAM

Le 10/17/08 5:54 PM, Mike a écrit :
Hello,
I am trying to pass a js array ,Round1[],

??? why to call it Something[] ? (name + brackets)
isn't it only : Something ?
to a form and send it. I can get it to work with serialized values but
I want to send the data as an array.
The arrays are filled with data. I am getting an error.

in the JS:

Round1 = ['apple','lemon','pear'];
document.forms['aJaX'].Result1[].value = Round1[];

no !

document.forms['aJaX']['Result1[]'].value = Round1;

document.forms['formName'].elements['elementName']

or in short way :
document.formName.elementName
but that doesn't work if the element's name is Name[]
(if the name has '[]')

here the name of the element is 'Round1[]'
so to call this element :
document.forms['aJax'].elements['Result1[]']

What is Round1[] in ...value = Round1[] ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top