You can use the hidden attribute (or just .hide() , display: none ) to temporarily hide the required parameter, which makes it impossible to select:
var $second = $('.select-two'); $('.select-one').change(function() { $second.find('option').prop('hidden', false) .filter('[value="' + $(this).val() + '"]').prop('hidden', true); $(this).val() == $second.val() && $second.val(''); });
http://jsfiddle.net/FDRE7/
And, of course, we can make it work in both directions:
var $select = $('.select').change(function() { var $other = $select.not(this); $select.find('option').prop('hidden', false) .filter('[value="' + $(this).val() + '"]').prop('hidden', true); $(this).val() == $other.val() && $other.val(''); });
http://jsfiddle.net/FDRE7/1/
You can also check this data on the server side. In this case, if the user selects the same values, then the POST array will look like this:
Array ( [name] => Array ( [0] => mercedes [1] => mercedes ) )
So it's pretty easy to check:
if ($_POST['name'][0] == $_POST['name'][1]) { // not allowed, redirect back }
or
if (count(array_unique($_POST['name'])) == 1) { // not allowed, redirect back }
source share