...

View Full Version : javasctipt and forms with array fields



anubis
09-20-2005, 11:33 AM
i can use a command such as ->


window.document.demo.test.value = "updated1";

to update a text field in a form like ->


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


However i want to start using array fields like ->


<input name="test[]" type="text">

But cant work out what i would need in javascript to do the same, any ideas?

nikkiH
09-20-2005, 03:27 PM
Warning: brackets in a name can lead to interesting dilemmas later. ;)
I'm not sure if they are valid html. Might be. Might not be. You might want to check before you start using that. If it isn't valid, some browsers might puke.

That said:
document.demo.elements["test[]"].value="whatever";

anubis
09-20-2005, 05:23 PM
cheers for that mike, works a treat..

i did read on php.net they are used to pass an array though from a form, to php, appose to say having a list of names and passing all that data across thought the url. So long as that holds up i am fine, as the data gets saves in a database.

Thanks for your help...

anubis
09-20-2005, 05:42 PM
seem to have found a problem, when using a for next loop.

this works fine.

document.demo.elements["test[1]"].value="whatever";

however this wont


var i = 1;
document.demo.elements["test[i]"].value="whatever";



any ideas????

nikkiH
09-20-2005, 05:54 PM
It's a string. It is not evaluated as a number. Unless...

document.demo.elements["test["+i+"]"].value="whatever";

:D

anubis
09-20-2005, 06:14 PM
:thumbsup:

cheers... at last...... you've been very helpfull, cheers



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum