Question
--> use strict; var formValidity = true; /* validate required fields */ function validateRequired() { var inputElements = document.querySelectorAll( #contactinfo input); var errorDiv = document.getElementById(errorText);
-->
"use strict";
var formValidity = true;
/* validate required fields */
function validateRequired() {
var inputElements = document.querySelectorAll(
"#contactinfo input");
var errorDiv = document.getElementById("errorText");
var elementCount = inputElements.length;
var requiredValidity = true;
var currentElement;
try {
for (var i = 0; i
// validate all input elements in fieldset
currentElement = inputElements[i];
if (currentElement.value === "") {
currentElement.style.background = "rgb(255,233,233)";
requiredValidity = false;
} else {
currentElement.style.background = "white";
}
}
if (requiredValidity === false) {
throw "Please complete all fields.";
}
errorDiv.style.display =
errorDiv.innerHTML = ""none";
}
catch(msg) {
errorDiv.style.display =
errorDiv.innerHTML = msg;
formValidity = false;
}
}
/* create event listeners */
function createEventListeners() {
alert(2);
var form = document.getElementsByTagName("form")[0];
if (form.addEventListener) {
form.addEventListener("submit", validateForm, false);
} else if (form.attachEvent) {
form.attachEvent("onsubmit", validateForm);
}
}
/* create event listeners */
function createEventListeners() {
var form = document.getElementsByTagName("form")[0];
if (form.addEventListener) {
form.addEventListener("submit", validateForm, false);
} else if (form.attachEvent) {
form.attachEvent("onsubmit", validateForm)
}
}
/* validate form */
function validateForm(evt) {
if (evt.preventDefault) {
evt.preventDefault(); // prevent form from submitting
} else {
evt.returnValue = false; // prevent form from submitting in IE8
}
formValidity = true; // reset value for revalidation
validateRequired();
if (formValidity === true) {
document.getElementsByTagName("form")[0].submit();
}
}
/* run setup functions when page finishes loading */
if (window.addEventListener) {
window.addEventListener("load", createEventListeners, false);
} else if (window.attachEvent) {
window.attachEvent("onload", createEventListeners);
}
/* validate number fields for older browsers */
function validateNumbers() {
var numberInputs = document.querySelectorAll("#contactinfo input[type=number]");
var elementCount = numberInputs.length;
var numErrorDiv = document.getElementById("numErrorText");
var numbersValidity = true;
var currentElement;
try {
for (var i = 0; i
// validate all input elements of type "number" in fieldset
currentElement = numberInputs[i];
if (isNaN(currentElement.value) || (currentElement.value=== "")) {
currentElement.style.background = "rgb(255,233,233)";
numbersValidity = false;
} else {
currentElement.style.background = "white";
}
}
if (numbersValidity === false) {
throw "Zip and Social Security values must be numbers.";
}
numErrorDiv.style.display = "none";
numErrorDiv.innerHTML = "";
}
catch(msg) {
numErrorDiv.style.display = "block";
numErrorDiv.innerHTML = msg;
formValidity = false;
}
}
function validateForm(evt) {
if (evt.preventDefault) {
evt.preventDefault(); // prevent form from submitting
} else {
evt.returnValue = false; // prevent form from submitting in IE8
formValidity = true; // reset value for revalidation
validateRequired();
validateNumbers();
if (formValidity === true) {
document.getElementsByTagName("form")[0].submit();
}
}
View Search Go Window # Help index.htm CIST 1520 Chapter06/HandsOnProject - Index.htm meta name="viewport" content="width-device-width, initial-scale=1.0">Personal Information
com action results.ht"> fieldset idcontactinto City - State/Province Label torripingut Zip/Postal CodePersonal Information
com action results.ht"> fieldset idcontactinto City - State/Province Label torripingut Zip/Postal CodeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started