Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 1.13 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. JS jQuery - check if value is in array
  2. var ar = ["value1", "value2", "value3", "value4"]; // ETC...
  3.  
  4.         jQuery(document).ready(function() {
  5.  
  6.             jQuery("form#searchreport").submit(function() {
  7.             if (jQuery.inArray(jQuery("input:first"), ar)){
  8.                       //if (jQuery("input:first").val() == "value11") { // works for single words
  9.             jQuery("#divResult").html("<span>VALUE FOUND</span>").show();
  10.             jQuery("#contentresults").delay(800).show("slow");
  11.                 return false;
  12.               }
  13.  
  14.         // SINGLE VALUE SPECIAL CASE / Value not allowed
  15.                if (jQuery("input:first").val() == "word10") {
  16.  
  17.                 jQuery("#divResult").html("YOU CHEAT !").show();
  18.                 jQuery("#contentresults").delay(800).show("slow");
  19.  
  20.                 return false;
  21.               }
  22.  
  23.         // Value not Valid
  24.  
  25.               jQuery("#divResult").text("Not valid!").show().fadeOut(1000);
  26.  
  27.               return false;
  28.             });
  29.  
  30.         });
  31.        
  32. if (jQuery.inArray(jQuery("input:first").val(), ar) != -1)
  33.        
  34. if(jQuery.inArray(el,arr) == -1){
  35.     // the element is not in the array
  36. };