Forum Moderators: open

Message Too Old, No Replies

form select multiple array acces with JS and PHP

         

Checkerbelt

7:26 am on Feb 28, 2005 (gmt 0)



I understand that to access a multiple select form element through $_POST in PHP, one must name the select element with the extra brackets.
ex: <select name="ids[]">

I want to validate the select data with javascript before posting using DOM. (I've named the form "formname".)
for (ndx = 0; ndx < document.formname.ids.length; ndx++) {
if (document.formname.ids[ndx] == 'dude') // do something
}

It seems javascript needs the name without the brackets for DOM array access.
ex: <select name="ids">

How can I create a select multiple form element accessible through both javascript and then through the $_POST in PHP upon submission? It seems the two languages are in conflict when it comes to form arrays.

Bernard Marx

8:00 am on Feb 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Good morning.

for (ndx = 0; ndx < document.formname.ids.length; ndx++) { 
if (document.formname["ids[]"][ndx] == 'dude') // do something
}

[blue]object.propName <--> object["propName"][/blue]