The codes posted might be not consistent because I am continuing someone's work and trying not to make too much changes if possible. Anyways, there's this form which has inputs for others to input values. upon submitting, if the input field is empty an alert will pop up and should stop the form from submitting.
I have tried using both return false; and event.preventDefault(); inside the if input field is empty but the form still submits.
trying to cut this short because the script is hell lots
just a simple form
<form action="cart.php" method="post" name="ordering" id="ordering" onsubmit="addDesc();">
<button type="submit" class="add-to-cart" alt='Add this product to your shopping cart now.'>Add to Cart <span class="fa fa-cart-plus"></span></button>
</form>
the function
function addDesc(desc){
// some variables to be passed when form submits
// an $.each function to loop through something
//inside the loop it'll push input values into an array called checkEmpty
if(jQuery.inArray("", checkEmpty) !== -1){
alert('Please Do not leave any input fields empty.');
return false;
}else{
//some outputs
}
}
return false is the first I tried but form still submitted.
I even tried something like
$('.add-to-cart').on('click', addDesc(event));
and inside addDesc() instead of return false I used event.preventDefault()
Thanks in advance.