Add JavaScript code to produce an error message and suppress submission of the f
ID: 650885 • Letter: A
Question
Add JavaScript code to produce an error message and suppress submission of the form if any quantity field contains non-numeric data. (It's OK for a quantity to be empty, but if it's non-empty, it must have only numbers.) Add an action= attribute to your <form> tag to submit the form to http://weblab.spsu.edu/formtest.php. Test that the form is submitted correctly when the quantities are numeric or empty, and that an error message is produced otherwise. (Regular expressions are your friend. Anything that's not a digit is bad. What is the predefined class for non-digits?)
Explanation / Answer
since i am not able to see your form id here creating a pseudo form for understanding
<script>
function validateForm(){
var x=document.forms["myForm"]["age"].value;
if (isNaN(x)) {
alert("Age Must be numberical value");
return false;
}
}
</script>
<form name="myForm">
<label for="firstname">Age: </label>
<input name="num" type="text" id="username" size="1">
<input type="submit" value="Login">
</form>
// Nan is function that determines whether a value is an illegal number (Not-a-Number).
This function returns true if the value is NaN, and false if not.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.