Created
July 20, 2013 05:53
-
-
Save spsaucier/6044024 to your computer and use it in GitHub Desktop.
Delivery Form with jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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