I have a load of dropdowns on a page (up to 1000), set as follows:
< select name="select< ?php print($select); ?>" id="select< ?php print($select); ?>">
So each gets a name and id selectX where X is a number between 1 and 1000.
Each has the 开发者_如何学Cvalues
- 1 2 3 4 5when the page loads, each is set to -
each time someone selects a value (except -) I need to make sure it has not been selected before. If it has, all other dropdowns with that value need to be set back to -
SO for example
dropdown 1 is set to - dropdown 2 is set to - dropdown 3 is set to - dropdown 4 is set to -a user sets the selected value in dropdown 2 to '4'.
this means we now have the values:
dropdown 1 is set to - dropdown 2 is set to 4 dropdown 3 is set to - dropdown 4 is set to -the user then sets the value of dropdown 3 to '5'. 5 is not set anywhere else so this works.
this means we now have the values:
dropdown 1 is set to - dropdown 2 is set to 4 dropdown 3 is set to 5 dropdown 4 is set to -the user then sets the value of dropdown 1 to '4'. 4 is already in use by dropdown 2, so dropdown 2 is set back to -
this means we now have the values:
dropdown 1 is set to 4 dropdown 2 is set to - dropdown 3 is set to 5 dropdown 4 is set to -I hope this makes sense? The number of dropdowns and their names will depend on various user settings so it could be anywhere from 10 - 1000.
Can anyone help at all?
Might be in your interest to name them "select_name[]", which will make processing the PHP on the server side much easier, and also validating on the client side. Arrays are your friend.
You can select the dropdowns by their name (if you did the first thing, and gave them all the same name), alternatively, you could give them a single class name and grab them by class. On the change event of each element in this array of dropdowns check if/who has a value clashing with the value just selected (loop through the array of dropdowns you grabbed above), and reset those who have clashing values.
The key point here is array, array, array.
Why do you have 1000 dropdowns?
Are you intentionally abusing your user base?
精彩评论