Skip to main content
gamedev.net
🔒 Locked

[web] Javascript form inputs

Started by Fyorl Feb 15, 2006 at 2:31 PM 1 replies 600+ views
Original Post
Fyorl
Fyorl
I'm not sure whether this is in the right forum or not but here goes anyway. Say I've got a form setup like the following:
<form action="index.php" name="list" method="post">
<input type="text" name="txt[]" value="" />
<input type="submit" name="submit" value="Submit" />
</form>
And I've got a piece of &#106avascript to add another input box each time a button is clicked (it's actually set up with divs and stuff but for simplicity's sake I'll just refer to the above one). The &#106avascript needs to be able to select the value of &#111;ne of those input boxes. In firefox the following gives a syntax error: document.list.txt[].value (which is understandable) but this apparently has no value: document.list.txt[0].value. When I change the value of the input box so that it isn't empty I get the same results. There is a workaround involving names like txt_1 and looping through them. But I'd rather not do that because it creates extra code &#111;n the &#106avascript as well as the PHP side. I just want to know if there is a way of getting the value of an array of input boxes. Any help would be welcome. Thanks, Fyorl
markr
markr
Having field names like txt[] is a PHP thing.

In &#106avascript you'd need to do:<br><br>document.forms[0]['txt[]'][0]<br><br>Or something.<br><br>Mark
Fyorl
Fyorl
hmm thanks for the reply, it doesn't seem to work though, I get an error saying the object has no properties.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.