Skip to content

Instantly share code, notes, and snippets.

@spsaucier
Created July 20, 2013 05:53
Show Gist options
  • Select an option

  • Save spsaucier/6044024 to your computer and use it in GitHub Desktop.

Select an option

Save spsaucier/6044024 to your computer and use it in GitHub Desktop.
Delivery Form with jQuery
<form id="checkDelivery">
<label for="postcode">Enter your postcode</label>
<input type="text" required name="postcode"/>
<button class="button">Submit</button>
</form>
<div id="delivery_options"></div>
<script>
$('#checkDelivery').submit(function() {
var data = $(this).serializeArray(),
postcodes = [2015,2019,2011];
jQuery.each(data, function(i, field){
if ( $.inArray(parseInt(field.value), postcodes) != -1 ) {
$('#delivery_options').html('<p>Yes, we deliver to your area!</p>');
}
else {
$('#delivery_options').html('<p>Unfortunately, we do not deliver to your area.</p>');
}
});
return false;
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment