I have a JavaScript function in my head part of my HTML
<script>
function validateForm()
{
var apple = document.getElementById('apple').value;
var err = 0;
if (isNaN(apple)) {
err += 1;
}
if (err != 0) {
alert('Please check your input!');
return false;
}
else
return true;
}
</script>
The form is shown below:
<form name="orderForm" onSubmit="return validateForm();" method="post">
<div class="input-control text span5">
<input class="span5" type="text" placeholder="Each @ $4.9" id="apple" name="apple" onChange='checkApple(this.value)'>
</div>
</form>
all brackets are completed and there is no typo.
When I submit the form with non numerical values, the form still gets submitted instead of error. May I know what's wrong with this ?
<input type="number" .../><script type="text/javascript">instead of<script>