I am looking for a solution to prevent duplicate selections in multiple select dropdowns. I want to alert the user if they have chosen the same value in more than one dropdown. Should I assign different IDs to each dropdown or is it possible to use just one ID for all of them? The duplicated selection should be highlighted in red.
<form method="post" action="">
<select name="drop1" id="drop1" onchange="checkDropdowns()">
<option value=" " selected="selected"> </option>
...
My JavaScript function is as follows:
function checkDropdowns()
{
var iDropdowns = 4;
var sValue;
var sValue2;
for(var i = 1; i <= iDropdowns; ++i)
{
sValue = document.getElementById('drop' + i).value;
...
}
return true;
}
I seem to be encountering an issue with my implementation. Any guidance or suggestions would be greatly appreciated.
For reference, here is my
Fiddle