I have a simple drop-down select menu with HTML. When I click an option, its value gets added to an array called exceptions
. I want to make sure the option value does not already exist in the array exceptions
, and if it does cancel the entire function with return
. It is all working except the part of function loop()
that compares each element of array exceptions
to the option clicked.
exceptions = new Array();
$(document).ready(function() {
$('select').click(function() {
var clicked = $(this).val();
loop(exceptions,clicked);
exceptions.push( clicked );
});
});
function loop(array,clicked) {
for (var i=0;i<array.length;i++) {
if (array[i] == clicked) {return;}
}
}