
Untitled
By: a guest on
Aug 12th, 2012 | syntax:
None | size: 1.13 KB | hits: 7 | expires: Never
JS jQuery - check if value is in array
var ar = ["value1", "value2", "value3", "value4"]; // ETC...
jQuery(document).ready(function() {
jQuery("form#searchreport").submit(function() {
if (jQuery.inArray(jQuery("input:first"), ar)){
//if (jQuery("input:first").val() == "value11") { // works for single words
jQuery("#divResult").html("<span>VALUE FOUND</span>").show();
jQuery("#contentresults").delay(800).show("slow");
return false;
}
// SINGLE VALUE SPECIAL CASE / Value not allowed
if (jQuery("input:first").val() == "word10") {
jQuery("#divResult").html("YOU CHEAT !").show();
jQuery("#contentresults").delay(800).show("slow");
return false;
}
// Value not Valid
jQuery("#divResult").text("Not valid!").show().fadeOut(1000);
return false;
});
});
if (jQuery.inArray(jQuery("input:first").val(), ar) != -1)
if(jQuery.inArray(el,arr) == -1){
// the element is not in the array
};