Forum Moderators: open

Message Too Old, No Replies

access each element of the control array

         

jasons

11:16 pm on Feb 18, 2006 (gmt 0)

10+ Year Member



I have code as follows,
<select name="menu[]" onchange="change()">
<option>...</option>
...
</select>
<select name="menu[]" onchange="change()">
<option>...</option>
...
</select>
and on and on...

this is generated by php server side code. but on the client side, change() has to be able to know WHICH menu was changed? any ideas? really appreciate it.

kaled

1:25 am on Feb 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<select name="menu1" onchange="changeSel(this)">

function changeSel(mySel)
{ alert(this.name);
}

NOTE: So far as I am aware:-
1) '[' and ']' are not valid identifier characters.
2) No two objects within a single form should have the same name (except radio boxes).

Kaled.

Bernard Marx

11:34 am on Feb 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1) [ and ] are valid characters in a name attribute, and, for PHP, they must be used when a name is used more then once, else an array won't be created at the server.

2) It's OK for any type of elements to share a name. Radios and checkboxes are the most common, but 2 selects is fine.

Bernard Marx

2:24 pm on Feb 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



WHICH menu was changed?

It all depends on what you want to do with the information. Using

this
in the event handler is the best start, and may be all you need. It will pass in a reference to the element itself. If you need some more information, you could do a little analysis to find out the index of the element in the collection, or you could identify each select with a different id attribute.