问题
Is there a jQuery, javascript, or .php script that would allow me to display different pages based upon a list of zip codes? For example, if the user enters a zip code within a list of 'valid' zips then pageA.php would display, if not then pageB.php would be displayed. These zip code values could be manually listed out, or be contained within a .csv file, whatever is easiest.
The page displayed after input would be based upon user input like:
<input name="zipcode" id="zipcode" type="text" />
the valid zip codes ideally would be listed as:
<script>
var zipcodelist = ['12345','12346','12347','12348'];
UPDATED SOLUTION this is the code i'm using:
<script type="text/javascript">
$(function(){
var zipCodes = ['92056', '90210', '92121', '92101'];
$('#zip_form').submit(function(){
$('#id_div_one, #id_div_two').hide();
var theZip = $('#id_zip_code').val();
if(jQuery.inArray(theZip,zipCodes) > -1) {
$('#id_div_one').fadeIn();
} else {
$('#id_div_two').fadeIn();
}
return false;
});
});
</script>
回答1:
You would probably just take the posted value for the zip code and then in your application logic just redirect to the page you want. For example in PHP:
$special_zip_codes = array(
'10000',
'10002',
'10003' // and so forth
);
$zip = $_POST['zip_code'];
// need to add whatever validation/sanitation of zip code value here
if(in_array($zip, $special_zip_codes)) {
header('Location: http://www.domain.com/fileA.php');
} else {
header('Location: http://www.domain.com/fileB.php');
}
exit();
回答2:
Make a php file which will take the data from the html file ( which has the pincode) say using post or get And then check from the excel sheet or DB the pincode and do what is required.
来源:https://stackoverflow.com/questions/11765410/how-to-display-different-pages-based-upon-form-input-value-ie-zip-code-jquer