Question

Modify the following file, so that: If the user input for the age input box is...

Modify the following file, so that:

  • If the user input for the age input box is empty, please send the user a warning message: “Age field cannot be empty” and return to 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. less than 1), please also send the user a warning message: “Your age input is not correct!” and return to the form web page to allow the user 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 box userAge.
// 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>

0 0
Add a comment Improve this question Transcribed image text
Answer #1

<!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 box userAge.
// if (document.getElementById("userAge").value) {
// if (document.f.userAge.value < 18) {

// checking if the age is empty
if(document.getElementById("userAge").value==""){
alert("Age field cannot be empty.");
return false;
}
//checking if the age is less than 1
if(document.getElementById("userAge").value<1){
alert("Your age input is not correct!");
return false;
}

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>

Add a comment
Know the answer?
Add Answer to:
Modify the following file, so that: If the user input for the age input box is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using JavaScript, I want to make a function that will open a new alert box that will say hello fi...

    Using JavaScript, I want to make a function that will open a new alert box that will say hello first name, last name after the person logs into the sign in form. This will happen aftrer the validation function is invoked. See code below. See the welcomefunction(). <!DOCTYPE html> <html> <head> <script> //validate the login form function validateForm() { var x = document.forms["LoginForm"]["fname"].value; //set x and y to first name and last name var y = document.forms["LoginForm"]["lname"].value; if (x ==...

  • Modify this code to store the form elements as variables and display them on the page...

    Modify this code to store the form elements as variables and display them on the page in an HTML table. <!DOCTYPE html> <html> <head> <script> function getValues() {     var result = ""; result += "First Name: " + document.forms["myForm"]["fname"].value + "<br>"; result += "Last Name: " + document.forms["myForm"]["lname"].value + "<br>"; result += "Address: " + document.forms["myForm"]["address"].value + "<br>"; result += "City: " + document.forms["myForm"]["city"].value + "<br>"; result += "State: " + document.forms["myForm"]["state"].value + "<br>"; document.getElementById("output").innerHTML = result; } </script>...

  • <html>     <head>       <title>Sign Up page</title>   <form name="validationForm" method="post" onsubmit="return checkvalidation()">      &n

    <html>     <head>       <title>Sign Up page</title>   <form name="validationForm" method="post" onsubmit="return checkvalidation()">         <!--div class-->       <div class="formvalidation">       <label>Your first Name</label>        <span id="showname"></span>        <!--label for firstname-->       <input type="text" name="firstname" class="formsignup"  id ="firstn" placeholder="Enter your Name">      <br><br>           <!--lastname-->       <label>Your last Name</label> <span id="showlname"></span>       <input type="text" name="lastname" class="formsignup" id="lastn" placeholder="Enter your last Name">       <br><br>        <!--email-->         <label>Your Email</label>          <span id="showemail"></span>         <input type="email" name="emailid" class="formsignup" size="45" id="emailn" placeholder="Enter your Email">        <br><br> <input type="submit" value="send">     </div>           </form> <script>      function checkvalidation(){     var name = document.forms["validationForm"]["firstname"].value;     var lname...

  • How can I print the Database table in PHP please ? here I have form for name and email, also I have php code that allow...

    How can I print the Database table in PHP please ? here I have form for name and email, also I have php code that allow user to add his name and email to my database, all I need to print my final database when the user click on submit. <form action="" method="post"> <label>Name :</label> <input type="text" name="name" required="required" placeholder="Please Enter Name"/><br /><br /> <label>Email :</label> <input type="email" name="email" required="required" /><br/><br /> <input type="submit" value=" Submit " name="submit"/><br /> </form>...

  • Hello! I am to create a .js file that allows the paragraph on the bottom of...

    Hello! I am to create a .js file that allows the paragraph on the bottom of the page to update with what the user enters. I need to modify the given HTML to recognize the javascript file that I am to make from scratch. The HTML file and other details are below: Use the given HTML to add functionality to an interactive form that generates an invitation to volunteers for an event. The file will have the following invitation message...

  • NEED HELP with HTML with Javascript embedding for form validation project below. I have my code...

    NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...

  • Using form events functions to answer this question. Use the attached form html file which contains...

    Using form events functions to answer this question. Use the attached form html file which contains 2 html radio buttons. When the first choice is chosen, display the text ”First” under the first choice. When the second choice is chosen, display the text ”Second” under the second choice. Instead of using JavaScript complete this question using JQuery <!DOCTYPE html> <html> <head>     <title>midterm exam</title>     <link rel="stylesheet" href="css/q1.css" /> </head> <body>     <div id = "page">        <form>   ...

  • Develop the Change Calculator application In this exercise, you’ll create an application that displays the minimum...

    Develop the Change Calculator application In this exercise, you’ll create an application that displays the minimum number of quarters, dimes, nickels, and pennies that make up the number of cents specified by the user. Without the use of a JavaScript Library (for coins). 1.      Open the HTML and JavaScript files below: 2.      In the JavaScript file, note that three functions are supplied. The $ function. The start of a calculateChange function. And an onload event handler that attaches the calculateChange...

  • LANGUAGE JAVASCRIPT, PHP Need help with PHP and ajax code. The user needs to login but,...

    LANGUAGE JAVASCRIPT, PHP Need help with PHP and ajax code. The user needs to login but, I keep getting an error that I coded "Wrong username and password!" ***PLEASE DONT GIVE ME A NEW CODE THAT IS NOWHERE NEAR THE CODE I SUBMITTED***** PLEASE LOOK AT THE CODE AND SEE ANY ISSUES login.html <!DOCTYPE html> <html> <head> <title>login popup</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <style type="text/css"> body { background-color: white; } </style> </head> <body> <center> <h1 style="text-align: center;"> Login </h1> <form>             Login ID:...

  • PHP code that is given : <?php // Here is where your preprocessing code goes //...

    PHP code that is given : <?php // Here is where your preprocessing code goes // An example is already given to you for the First Name $fname = $_GET['fname']; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Exercise 2 - GET Echo</title> <style> body { margin:0; padding:0; font-family: Arial; } form { margin:20px; } input[type="text"], input[type="password"] { width:150px; padding:3px; font-size:1em; } input[type="submit"] { padding:3px; font-size:1em; } label { display:inline-block; width:150px; } .input-container { padding:5px; } </style> </head> <body> <form...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT