Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

--> use strict; var formValidity = true; /* validate required fields */ function validateRequired() { var inputElements = document.querySelectorAll( #contactinfo input); var errorDiv = document.getElementById(errorText);

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

-->

"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"> Hands-on Project 5-1 chody cheader chis Hands-on Project 6-1 articles

Personal Information

com action results.ht">
fieldset idcontactinto City - State/Province Label torripingut Zip/Postal Code Hands-on Project 5-1 chody cheader chis Hands-on Project 6-1 articles

Personal Information

com action results.ht">
fieldset idcontactinto City - State/Province Label torripingut Zip/Postal Code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 2 Lncs 13427

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124251, 978-3031124259

More Books

Students also viewed these Databases questions

Question

What about leadership lessons from particularly good or bad bosses?

Answered: 1 week ago

Question

How would you assess the value of an approach like this?

Answered: 1 week ago