How can i have three or more select tags with same names(as in my program, the select tags are being generated dynamically), and select independently what option was selected.
I have a loop, where my php reads a sql table, and for each row, it creats a select tag and a button with it.
<select name="vote">
<option value="1">1</vote>
<option value="2">2</vote>
<option value="3">3</vote>
</select>
<input type="button" onclick="vote()">
So suppose i have 3 rows in my sql table, so 3 select tags with buttons would be created.
Now my question is how can i see what select tag has what option seleted??
Can anyone help me with this.
Zeeshan
When you have multiple elements in a form with identical
nameattributes, they become a collection (essentially, an array) in the DOM.So where you might have one select like this
You would access the select element like so
Now, if you had 2 or more, like this
You would access them in the DOM like this
EDIT
Oh, on the PHP end, it won’t recognize multiple values unless you add
[]to the name – this tells PHP to not replace same-key-name values, but rather use them as an array.Then, you would read these values like so