0

This is the code that I currently have:

<script>
var zips = ['30068', '90120','30033'];
$(function(){
  $('input[name=zip]').change(function(){
    var currentVal = $(this).val(); 
    if(!$.inArray(currentVal, zips)){
       $('.checkout_button').prop('disabled',true);
    } else {
       $('.checkout_button').prop('disabled',false);
      }
    });
});
</script>

I want it so that when the user types in their zip code it sees if we support their service or not. This works currently but only works with 30068. By this, I mean that if I type in 90120 it runs the wrong response unlike 30068. Basically, only the first item of the array correctly works? Why is this?

If You Believe This Is A Duplicate Please Explain So I Can Change My Answer.

5
  • 1
    api.jquery.com/jquery.inArray Commented Dec 15, 2017 at 21:55
  • 1
    should be if($.inArray(currentVal, zips) === -1){, as it does not return a boolean but an index. Commented Dec 15, 2017 at 21:57
  • @trincot I changed it to what you said and it has not worked. Commented Dec 15, 2017 at 22:11
  • 1
    Post a minimal reproducible example please which would include the HTML Commented Dec 15, 2017 at 22:13
  • 1
    I would rather use keyup, but, basically - code should work: jsfiddle.net/qyn2rdot Commented Dec 15, 2017 at 22:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.