473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Passing an Array to a form field

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
Oct 17 '08 #1
2 2977
Mike wrote:
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(',');

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 17 '08 #2
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[] ?

--
sm
Oct 17 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Phillip Wu | last post by:
Hi, I saw a previous post about sending arrays but did not quite understand the answers. The problem is that I would like to pass an entire array as a hidden input field from one php script...
5
by: Paul | last post by:
I want to use sessions to cover myself in case the user switches off cookies so I am passing the session ID manually through a hidden input field. This is what I have so far. index.php page...
1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
1
by: Kevin Lyons | last post by:
Hello, I am trying to get all of my form elements passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html to the following URL:...
8
by: kalinga1234 | last post by:
there is a problem regarding passing array of characters to another function(without using structures,pointer etc,).can anybody help me to solve the problem.
2
by: Steve Turner | last post by:
I have read several interesting posts on passing structures to C dlls, but none seem to cover the following case. The structure (as seen in C) is as follows: typedef struct tag_scanparm { short...
13
by: Deano | last post by:
Apparently you can only do this with one value i.e Call MyAssetLocationZoom(Me!txtLocation, "Amend data") This runs; Public Sub MyAssetLocationZoom(ctl As Control, formName As String) On...
2
by: Garg | last post by:
Hi All, I am facing one problem if you are having any solution please tell me. I have to pass an array from javascript to servlet. for this i created one array and pass that through submitting...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.