Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
Set value of hidden input based on ZIP code entry

I am attempting to set arrays for specific regions and then compare them to the zip code entered to set the value of a hidden field (to name the region). Everything I enter sets the "Not Found". I'm stumped, any and all help would be greatly appreciated.

HTML:

<input id="zip" name="ZIPCODE" type="text" />
<input id="REGION" name="REGION" type="hidden" /> 

SCRIPT:

var eastZips = [19144, 19103, 19104];
var westZips = [90210, 90211, 90212];
        
    
$("#zip").keyup(function() {        
    if ($(this).val() == eastZips) {
        $("#REGION").val("East");
    } else if ($(this).val() == westZips) {
        $("#REGION").val("West");
    } else 
        $("#REGION").val("Not Found");
});  
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The value of the input will never match eastZips or westZips because you are comparing things that are not the same "type". With your stored variables being arrays and the input value being a string.

There are a few steps to take here to clear this up.

Although what you are inputing is a set of digits JS will read the field value as string, so you must make sure that you are processing that value to compare correctly to the integers you have stored. This is achievable by putting the field value through a parseInt

The next thing you want is to check if the input value is part of either array, this is achievable by using includes.

var eastZips = [19144, 19103, 19104];
var westZips = [90210, 90211, 90212];
        
    
$("#zip").keyup(function() {
  // Store input value for easier access, and wrap
  // it in a parseInt to ensure you are storing
  // an integer for comparison.
  var zip_value = parseInt( $(this).val() );

  // Check if either array stores the input value
  if ( eastZips.includes( zip_value ) ) {
    $("#REGION").val( "East" );
  } else if ( westZips.includes( zip_value ) ) {
    $("#REGION").val( "West" );
  } else {
    $("#REGION").val( "Not found" );
  }
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!