<select id="select">
<option value="1">1adsd</option>
<option value="2">2adsd</option>
<option value="3">3adsd</option>
<option value="4">4adsd</option>
<option value="5">5adsd</option>
</select>
var parray = ['2', '5'];
$("#select").live('change', function(){
if($.inArray($(this).val(), parray)){
console.log('yes');
console.log($(this).val());
console.log(parray);
} else {
console.log('no');
console.log($(this).val());
console.log(parray);
}
})
Why this doesnt working correctly?
if i select value 1 this show me ‘yes’ but “1” isnt in parray.
if i select value 2 this show me ‘no’ but “2” is in parray.
if i select value 5 this show me ‘yes’ – only this is OK. Why?
LIVE:
As the manual clearly states:
$.inArray returns -1 if the element is not found, or the index where the element has been found (beginning at 0) otherwise.