1

Not really sure what I have missed, but I would appreciate some help. I never get a true calculation.

function isValid(){
  var zipCode = $("input[name='zipCode']").val();
  var zipCodeRedRiverHonda = [ 11, 22, 33, 44 ];
  var zipCodeFentonHondaArdmore = [ 55, 66, 77, 88 ];

  var calculate = $.inArray(zipCode, zipCodeRedRiverHonda);

  if (calculate > -1) {
    alert("in Array!");
  }
  else {
    alert("Not in array");
  }
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>


<div id="contact-dealer">
  <h2>Zipcode check</h2>
  <form method="post" action="form.php" name="leadForm" onsubmit="return isValid();">
     <input type="text" name="zipCode"/>
     <br>
    <input class="submit" type="submit" name="submit" value="Get Info" id="Submit">
  </form>
</div>
chadbear
  • 29
  • 6

1 Answers1

5

You have to parse your value as an integer ("10" != 10):

var zipCode = parseInt($("input[name='zipCode']").val(), 10);
tymeJV
  • 103,943
  • 14
  • 161
  • 157