Passing array values to form fields
I'm trying to pass an array of values to a series of html form fields.
the data in the array is in the variables dirLen
the form fields I'm trying to populate are named
I can pass individual array values to the individual form fields using:
so I know my array is good and that the above syntax works.
I just don't know the format to call the form field in the following for-loop.
// for-loop to populate form fields
for (var k=0;k<=23;k++)
and lots of others. Any help is appreciated.
Did you try this one:
form['dirLen' + k].value = dirLen[k];
it's quite possible that you are referencing your form incorrectly. If you are just working with named fields (ie, no id's), easiest is to name your form.
you will also want to remove the dot between the form reference and the first square bracket, and also bear in mind that you are starting your loop off at 0 but your field names start at 1:
<input type="text" name="dirLen1"/>
<input type="text" name="dirLen2"/>
<input type="text" name="dirLen3"/>
bioniod: thanks, just what I was looking for. Worked perfectly.
xelawho: I still have some tweeking to do on the incrementing k+1 vs K etc. but needed to get over this hurdle first.
This is my first post here and I got a solution in a couple of hours. Awesome.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)