From W3schools example (do not make any comment about W3Schools I am just using it for an example). A select option looks like this:
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
Lets say that I have two select
options with the same name
<select name="name[]">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<select name="name[]">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
Now, what I want to accomplish using jQuery, that if somebody selected an option from the first select.. he/she cannot select it from the second select. How can I accomplish that? i.e. how can I automatically remove Volvo
from the second select if it was selected in the first select?
If it is not possible using jQuery, then how can I prevent it using PHP?
My guess is by using array_unique
:
foreach(array_unique($_POST['name']) as $name){
if (!empty($name)){
// do something
}
[Edit after posting the question]
this question is relevant to mine. However, I do not want the option to be disabled.. I want the option to be removed or hidden. Also, I would like to see how it can be done using PHP