(Solved) : Modify Following File User Input Age Input Box Empty Please Send User Warning Message Age Q37216922 . . .
Modify the following file, so that:
- If the user input for the age input box is empty, please sendthe user a warning message: “Age field cannot be empty” and returnto the form web page to allow the user to re-input the age;
If the user input for the age input box is incorrect (e. g. lessthan 1), please also send the user a warning message: “Your ageinput is not correct!” and return to the form web page to allow theuser to re-input the age
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Form Handling</title>
<meta charset=”utf-8″>
<style type=”text/css”>
div {padding-bottom:10px; width:250px; text-align:right; }
label {padding-right:5px; }
</style>
<script type=”text/javascript”>
<!–
function validateForm()
{
if (document.forms[0].userName.value == “” )
{alert(“Name field cannot be empty.”);
return false;
} // end if
// the two lines in comments will also work to access the input boxuserAge.
// if (document.getElementById(“userAge”).value) {
// if (document.f.userAge.value < 18) {
if (document.forms[0].userAge.value < 18)
{
alert(“Age is less than 18. You are not an adult”);
return false;
} // end if
alert(“Name and Age are valid.”);
return true;
} // end function validateForm
// –>
</script>
</head>
<body>
<h2>JavaScript Form Handling</h2>
<form method=”post”action=”http://webdevfoundations.net/scripts/formdemo.asp”onsubmit=”return validateForm( );”>
<div>
<label for=”userName”>Name:</label>
<input type=”text” name=”userName” id=”userName”>
</div>
<div>
<label for=”userAge”>Age:</label>
<input type=”text” name=”userAge” id=”userAge”>
</div>
<div>
<input type=”submit” value=”Send information”>
</div>
</form>
</body>
</html>
Expert Answer
Answer to Modify the following file, so that: If the user input for the age input box is empty, please send the user a warning mes…
OR