I am using javascript to display an error when user click on form submit button if the number entered is not in between min and max. The issue is when you click submit button the form will submit regardless. Can you please look at the code below and tell me what I need to add. I need to prevent form from submitting if the min and max condition is not fulfilled.
html
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="validation.js"></script></head>
<body>
<form name="form1" >
<label>Enter Amount</label>
<input id="amount" type="number" value="0" min="5" max="10" step="1"/>
<p id="error"></p>
<br/>
<label>Charity you wish to donate to</label>
<input type="text" name="charity"></input>
<br/>
<button id="save_choice" onclick="amountFunction()">Save Choice</button>
<button><a href="#" target="_blank">Save Choice</a></button>
</form>
<p id="error"></p>
</body>
</html>
javascript
var inpObj = document.getElementById("amount");
if (inpObj.checkValidity() == false) {
document.getElementById("error").innerHTML = inpObj.validationMessage;
return false
} else {
document.getElementById("error").innerHTML = "Input OK";
return true
}
}