Sign in
Log inSign up

How do I limit the amount of times the same option is selected within a group of dropdown lists?

Steven Ventimiglia's photo
Steven Ventimiglia
·Aug 30, 2018

Let's say I have three dropdown lists...

<select name="list-01">
    <option value="1">Option 001</option>
    <option value="2">Option 002</option>
    <option value="3">Option 003</option>
</select>

<select name="list-02">
    <option value="1">Option 001</option>
    <option value="2">Option 002</option>
    <option value="3">Option 003</option>
</select>

<select name="list-03">
    <option value="1">Option 001</option>
    <option value="2">Option 002</option>
    <option value="3">Option 003</option>
</select>

...how do I prevent a user from choosing Option 003, for all three selections?

All three can be Option 001 or Option 002. Any two can be Option 003, but as soon as you tried to select that for the third dropdown list, it would - for this example - give you an alert that you cannot choose that option for all three.

I'm also looking for this to be flexible enough that, if there were twelve dropdown lists, you would only be able to choose Option 003 for eleven of them.