samedi 16 décembre 2017

Return Value Based On Item In Different Arrays - jQuery

How would I determine what array an item is in jQuery? This is the code that I currently have:

var zips = ['30068', '90120','30033'];
var bad = ['314', '13567','1'];
$(function(){
  $('input[name=zip]').keyup(function(){
    var currentVal = $(this).val(); 
    if(!$.inArray(currentVal, zips)==-1){
     alert("if")
    } else if(!$.inArray(currentVal, bad)==-1){
     alert("else if")
    } else {
     alert("else")
      }
    });
});

What I want to happen is that when the user types in their zip code it decides what response to give. For example, if they type in 30033 then it would return if. If the user typed in 1 then it would return else if and if the user typed in anything else then it would return else. How would I do this?

Aucun commentaire:

Enregistrer un commentaire