The JavaScript code is given below. Check it and use all the validation checks, so that the program will have the form(structure) like in the given picture.  Form Validation       First Name:     Last Name: Email: User Id: Password: Confirm Password:

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

The JavaScript code is given below. Check it and use all the validation checks, so that the program will have the form(structure) like in the given picture.

<html>
<head>
 <title>Form Validation</title>
 <script type="text/javascript">

  var divs=new Array();
  divs[0]="errFirst";
  divs[1]="errLast";
  divs[2]="errEmail";
  divs[3]="errUid";
  divs[4]="errPassword";
  divs[5]="errConfirm";

  function validate()
  {
   var inputs=new Array();
   inputs[0]=document.getElementByld('first').value;
   inputs[1]=document.getElementByld('last').value;
   inputs[2]=document.getElementByld('email').value;
   inputs[3]=document.getElementByld('uid').value;
   inputs[4]=document.getElementByld('password').value;
   inputs[5]=document.getElementByld('confirm').value;
 
   var errors=new Array();
   errors[0]="<span style='color:red'>Please enter your first name!</span>";
   errors[1]="<span style='color:red'>Please enter your last name!</span>";
   errors[2]="<span style='color:red'>Please enter your email!</span>";
   errors[3]="<span style='color:red'>Please enter your user id!</span>";
   errors[4]="<span style='color:red'>Please enter your password!</span>";
   errors[5]="<span style='color:red'>Please confirm your password!</span>";

  for (i in inputs)
   {
    var errMessage=errors[i];
    var div=divs[i];
    if(inputs[i]=="")
       document.getElementByld(div).innerHTML=errMessage;
    else if (i==2)
     {
      var atpos=inputs[i].indexOf("@");
      var dotpos=inputs[i].lastIndexOf(".");
      if (atpos<1 || dotpos<atpos+2 || dotpos+2>=inputs[i].length)
         document.getElementByld('errEmail').innerHTML="<span style='color:red'>Enter a valid email address!</span>";
      else
         document.getElementByld(div).innerHTML="OK!";
      }
      else if (i==5)
      {
       var first=document.getElementByld('password').value;
       var second=document.getElementByld('confirm').value;

        if (second!=first)
           document.getElementByld('errConfirm').innerHTML="<span style='color:red'>Your passwords don't match!</span>";
        else
           document.getElementByld(div).innerHTML="OK!";
       }
       else
         document.getElementByld(div).innerHTML="OK!";
      }
     }

   function finalValidate()
   {
    var count=0;
   
    for(i=0;i<6;i++)
     {
      var div=divs[i];

      if(document.getElementByld(div).innerHTML=="OK!")
      count=count+1;
     }
     if(count==6)
       document.getElementByld("errFinal").innerHTML="All the data entered is correct!!!";
    }
 </script>
</head>

<body>
  <table id="table1">
 <tr>
<td>First Name:</td>
<td><input type="text" id="first" onkeyup="validate();"/></td>
<td><div id="errFirst"></div></td>
 </tr>

 <tr>
<td>Last Name:</td>
<td><input type="text" id="last" onkeyup="validate();"/></td>
<td><div id="errLast"></div></td>
</tr>

<tr>
<td>Email:</td>
<td><input type="text" id="email" onkeyup="validate();"/></td>
<td><div id="errEmail"></div></td>
</tr>

<tr>
<td>User Id:</td>
<td><input type="text" id="uid" onkeyup="validate();"/></td>
<td><div id="errUid"></div></td>
</tr>

<tr>
<td>Password:</td>
<td><input type="password" id="password" onkeyup="validate();"/></td>
<td><div id="errPassword"></div></td>
</tr>

<tr>
<td>Confirm Password:</td>
<td><input type="password" id="confirm" onkeyup="validate();"/></td>
<td><div id="errConfirm"></div></td>
</tr>

<tr>
<td><input type="button" id="create" value="Create" onclick="validate();finalValidate();"/></td>
<td><div id="errFinal"></div></td>
</tr>

</table>
</body>
</html>

First Name:
Last Name:
Email:
User Id:
Password:
Confirm Password:
Create
] Please enter your first name!
|Please enter your last name!
| Please enter your email!
|Please enter your user id!
| Please enter your password!
| Please confirm your password!
First Name:
Last Name:
Email:
User Id:
Password:
Confirm Password:
Create
First Name:
Ayesha
OK!
Lara
OK!
OK!
Last Name:
Email:
ays@yahoo.com
User Id:
12345
OK!
Password:
OK!
Confirm Password:
OK!
....
Create
All the data you entered is correct!!!
Transcribed Image Text:First Name: Last Name: Email: User Id: Password: Confirm Password: Create ] Please enter your first name! |Please enter your last name! | Please enter your email! |Please enter your user id! | Please enter your password! | Please confirm your password! First Name: Last Name: Email: User Id: Password: Confirm Password: Create First Name: Ayesha OK! Lara OK! OK! Last Name: Email: ays@yahoo.com User Id: 12345 OK! Password: OK! Confirm Password: OK! .... Create All the data you entered is correct!!!
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY