use JavaScript to add interaction and validation to your web page. First, add an
ID: 3658955 • Letter: U
Question
use JavaScript to add interaction and validation to your web page. First, add an input text box for the user's age. Next, create functions to validate the name, age, and item selection in a JavaScript file. Specifically, check for the following: The user has entered a name Age is a number between 18 and 110 An item is selected Ensure that a handler returns true if the input is acceptable and false otherwise. Add an on Submit attribute to the form tag so that a validation failure prevents the form submission. How can you tell whether the form submitted successfully or not? Modify your JavaScript so that it displays an appropriate confirmation or error message as an alert. see screen shoot for easy reference@
Explanation / Answer
validation:: function validateFormOnSubmit(theForm) { var reason = ""; reason += validateUsername(theForm.username); reason += validatePassword(theForm.pwd); reason += validateEmail(theForm.email); reason += validatePhone(theForm.phone); reason += validateEmpty(theForm.from); if (reason != "") { alert("Some fields need correction: " + reason); return false; } return true; }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.