Add a text box for the user\u2019s city to formvalidation.htmlEnsure th.docx - Add a text box for the user\u2019s city to formvalidation.html Ensure that the

Add a text box for the user’s city to formvalidation.htmlEnsure th.docx

This preview shows page 1 - 4 out of 5 pages.

Image of page 1
Add a text box for the user’s city to formvalidation.html Ensure that the text box is not empty when the form is submitted by inserting additional code to the function validateForm() which is located in the head of the document. If the text box is empty pop-up an appropriate alert message Do not submit the form if the text box is empty <!DOCTYPE html> <html lang=\"en\"> <head> <title>JavaScript Practice</title> <meta charset=\"utf-8\"> <style> input { display: block; margin-bottom: 1em; } label { float: left; width: 5em; padding-right: 1em; text-align: right; } #submit { margin-left: 7em; } </style> <script> function validateForm() { if (document.forms[0].userName.value == \"\" ) { alert(\"Name field cannot be empty.\"); return false;
Image of page 2
} // end if 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> <h1>JavaScript Form Handling</h1> <form method=\"post\" action=\"\ " onsubmit=\"return validateForm();\">
Image of page 3
Image of page 4

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture