Reputation: 382
Below is some script I'm using for a form. Everything works great except for the very last alert. It's pointing to input #address_province. If a customer's address is one of those in the list (shown for testing purposes are values WA, AL, GA) I'd like an alert, otherwise they can proceed. Currently nothing happens no matter what I put in the state field...I can proceed regardless. What am I doing wrong?
Thank you in advance!
<script>
// Hides shipping info fieldset if ship to billing is checked
$(function () {
$("#ship_to_billing").change(function () {
if ($(this).is(":checked")) $("#shipping_info").hide();
else $("#shipping_info").show();
});
});
// Validates address fields are filled out unless ship to billing is checked...
function validateShipping() {
if (!$("#ship_to_billing").is(":checked")) {
var inputs = $("#shipping_info input");
var ready = true;
inputs.each(function () {
if ($(this).val() == '') {
ready = false;
return false;
}
});
if (!ready) {
alert("Please tell us where to send this. Either choose ship to Billing Address or fill out both the Recipient Name as well as Shipping Address fields. Thanks!");
return false;
}
}
// Makes sure age verification is checked
if (!$('#age_verification').is(':checked')) {
alert("Please verify you are 21 years of age or older.");
return false;
}
}
// Confirms province is allowed for wine shipping
if (!$('#address_province').val() == "WA") {
alert("Shipping gifts containing alcohol to this state is prohibited by law. Please choose another item.");
return false;
}
return true;
}
</script>
Upvotes: 0
Views: 213
Reputation: 44526
The correct condition there would have to be:
if ($('#address_province').val() != "WA") {
EDIT
Also the primary issue as pointed out by @jsmorph in the comments is that the:
Your
}
before theif (!$('#address_province').val() == "WA") {
closes your functionvalidateShipping() {
.
Upvotes: 1