Forum Moderators: open
I want an alert('Must be a multiple of 3') if the user tries to submit the form if it's false.
I've done a lot of searching and have found nothing so far, any help would be greatly appreciated.
I'm sure the return false; in the following function should stop the form being submitted, but after I OK the alert, the form submits anyway. Am I missing something?
<script type="text/javascript">
function three(){
if ( document.orderform.qty.value % 3!= 0 )
{
alert("Total must be multiple of 3");
return false;
}
}
</script>
<form method="post" action="process.php" name="orderform" onsubmit="three();">
- It could be safe to explicitly return
true if the input is OK. (using:) onsubmit="return three([blue]this[/blue]);">function three(form){
var value = form.qty.value;
var OK = (value % 3 == 0) && ( value > 1 )
if (!OK )
alert("Total must be multiple of 3");
return OK;
}