SlideShare a Scribd company logo
Option #1: Form Validation in JavaScript
1. In your text editor, open the index.htm file from the HandsOnProject6-1 folder in the
Chapter06 folder , add your name and today's date where indicated in the comment section, and
then save the file. 2. Create a new document in your editor, add JavaScript comments containing
the text Hands-on Project6-1, your name, and today's date, and then save the file to the
HandsOnProject6-1 folder with the name script.js. 3. Return to the htm file in your browser,
within the body section, just before the closing /body tag, add a script element, and then specify
the file script.js as the source. 4. In the opening form tag, add code to disable browser-based
validation, and then save your changes. 5. In the script.js file, add code instructing processors to
interpret the contents in strict mode, and then create a global variable named formValidity and
set its value to true. 6. Add the following function to validate the required form elements: 7. Add
the following function to create an event lister for the submit event. 8. Add the following
function to trigger validation of required fields when the Submit button is clicked: 9. Add the
following code to call the createEventListeners() function when the page finishes loading. 1 /*
run setup functions when page finishes loading */ 2 if (window.addEventListner) { 3
window.addEventListner("load", createEventListenres, false); 4 } else if (window.attachEvent)
{ 5 window.attachEvent ("onload", createEventListeners); 6 } 10. Save your changes to
script.js, open index.htm in a browser, and then test various combinations of invalid and valid
data to ensure that the scripts you wrote behave as you expect. Debug your code as necessary
until it functions correctly. 11. Returntoscript.js in your editor, and then add the following
function to validate input elements with the number type: 1/ validate number fields for older
browsers % 2 function validate Numbers () { 3 var numberInputs = document.querySelectorAll
(H"#contactinfo input[type=number]"); 4 var elementCount = numberInputs.length; 5 var
numErrorDiv = document.getElementByld("numErrorText"); 6 var numbersValidity = true; 7
var currentElement; 8 try { 12. In the validateForm() function, add a call to the
validateNumbers() function as follows: 13. Save your changes to script.js, open index.htm in a
browser, and then test various combinations of invalid and valid data, including nonnumeric
entries in number fields, to ensure that the scripts you wrote behave as you expect. Debug your
code as necessary until it functions correctly.

More Related Content

PPTX
Form Validation in JavaScript
Ravi Bhadauria
 
PPTX
Web topic 22 validation on web forms
CK Yang
 
PDF
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
 
RTF
Html basics 11 form validation
H K
 
PPT
9781305078444 ppt ch06
Terry Yoast
 
PPTX
Javascript validating form
Jesus Obenita Jr.
 
KEY
Building & Breaking Web Forms with Quaid-JS
cliener
 
PDF
Web Forms People Don't Hate
cliener
 
Form Validation in JavaScript
Ravi Bhadauria
 
Web topic 22 validation on web forms
CK Yang
 
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
 
Html basics 11 form validation
H K
 
9781305078444 ppt ch06
Terry Yoast
 
Javascript validating form
Jesus Obenita Jr.
 
Building & Breaking Web Forms with Quaid-JS
cliener
 
Web Forms People Don't Hate
cliener
 

Similar to Option #1- Form Validation in JavaScript 1- In your text editor- open.docx (20)

PPTX
Form using html and java script validation
Maitree Patel
 
PPTX
Form Validation
Graeme Smith
 
DOCX
YASH HTML CODES
YashKoli22
 
DOCX
YASH HTML CODE
YashKoli22
 
DOCX
WEB DESIGN PRACTICLE bca
YashKoli22
 
KEY
HTML5 Form Validation
Ian Oxley
 
PDF
Form Validation NG
joaopmaia
 
PPT
Jquery validate - TuanNA
Framgia Vietnam
 
PPTX
Javascript ch7
Brady Cheng
 
PDF
A Sensational Exposé With Bewildering Demonstrations
Peter Gasston
 
PDF
JavaScript The Web Warrior Series 6th Edition Vodnik Solutions Manual
olasonhrncic
 
PPT
Lecture7 pattern
Châu Thanh Chương
 
PDF
JavaScript The Web Warrior Series 6th Edition Vodnik Solutions Manual
sunjidisacan
 
PDF
JavaScript The Web Warrior Series 6th Edition Vodnik Solutions Manual
prijajatari
 
PDF
Mid term exam
H K
 
PDF
JavaScript The Web Warrior Series 6th Edition Vodnik Solutions Manual
lmzhedyjxv5252
 
PDF
JavaScript The Web Warrior Series 6th Edition Vodnik Solutions Manual
amuedoliazid
 
PDF
JavaScript The Web Warrior Series 6th Edition Vodnik Solutions Manual
janethnastasihji
 
PDF
JavaScript The Web Warrior Series 6th Edition Vodnik Solutions Manual
parmasjadob
 
PDF
JavaScript The Web Warrior Series 6th Edition Vodnik Test Bank
sabogaraony
 
Form using html and java script validation
Maitree Patel
 
Form Validation
Graeme Smith
 
YASH HTML CODES
YashKoli22
 
YASH HTML CODE
YashKoli22
 
WEB DESIGN PRACTICLE bca
YashKoli22
 
HTML5 Form Validation
Ian Oxley
 
Form Validation NG
joaopmaia
 
Jquery validate - TuanNA
Framgia Vietnam
 
Javascript ch7
Brady Cheng
 
A Sensational Exposé With Bewildering Demonstrations
Peter Gasston
 
JavaScript The Web Warrior Series 6th Edition Vodnik Solutions Manual
olasonhrncic
 
Lecture7 pattern
Châu Thanh Chương
 
JavaScript The Web Warrior Series 6th Edition Vodnik Solutions Manual
sunjidisacan
 
JavaScript The Web Warrior Series 6th Edition Vodnik Solutions Manual
prijajatari
 
Mid term exam
H K
 
JavaScript The Web Warrior Series 6th Edition Vodnik Solutions Manual
lmzhedyjxv5252
 
JavaScript The Web Warrior Series 6th Edition Vodnik Solutions Manual
amuedoliazid
 
JavaScript The Web Warrior Series 6th Edition Vodnik Solutions Manual
janethnastasihji
 
JavaScript The Web Warrior Series 6th Edition Vodnik Solutions Manual
parmasjadob
 
JavaScript The Web Warrior Series 6th Edition Vodnik Test Bank
sabogaraony
 

More from farrahkur54 (20)

DOCX
PARTICIPANTS PROFILE ANSWER ABOVE MENTIONED QUESTIONS BY TAKING CARE.docx
farrahkur54
 
DOCX
Part3- Offline traffic monitoring In this part will use a PCAP file to.docx
farrahkur54
 
DOCX
Participation is a requirement of this course- Students provide one po.docx
farrahkur54
 
DOCX
Partners Johnny and Daniel each have capital balances of $95-000- Migu.docx
farrahkur54
 
DOCX
Parthians- write one to two paragraphs on the significance of this ite.docx
farrahkur54
 
DOCX
P(X-x).docx
farrahkur54
 
DOCX
Overview You are required to prepare a Data Entry report which provide.docx
farrahkur54
 
DOCX
package edu-ser222-m03_02- --- - A binary search tree based impleme.docx
farrahkur54
 
DOCX
P(A)+P(A)-1 is one way to express the P(A)+P(A)-1 is one way to expres.docx
farrahkur54
 
DOCX
P(Z-0-86).docx
farrahkur54
 
DOCX
Overton Company has gathered the following information-Compute equival.docx
farrahkur54
 
DOCX
Over 1 million Americans make a living working for advertising and pub.docx
farrahkur54
 
DOCX
Oscar is suing John for $1000 dollars but the judge sees that their ar.docx
farrahkur54
 
DOCX
Organizational Behavior Chapter 5 - Perception and Indigidual Decision.docx
farrahkur54
 
DOCX
ook at the mean- median- mode- and standard deviation and describe how.docx
farrahkur54
 
DOCX
Option #1- Creating a GUI Bank Balance Application Create a simple Gr.docx
farrahkur54
 
DOCX
Operational Metrics and Benchmarking in Healthcare- What are common op.docx
farrahkur54
 
DOCX
One of the duties and functions of the joint OHS committee is to ensur.docx
farrahkur54
 
DOCX
One of the deadliest heart conditions is a disturbance in heart rhythm.docx
farrahkur54
 
DOCX
Once you have all the structures working as intended- it is time to co.docx
farrahkur54
 
PARTICIPANTS PROFILE ANSWER ABOVE MENTIONED QUESTIONS BY TAKING CARE.docx
farrahkur54
 
Part3- Offline traffic monitoring In this part will use a PCAP file to.docx
farrahkur54
 
Participation is a requirement of this course- Students provide one po.docx
farrahkur54
 
Partners Johnny and Daniel each have capital balances of $95-000- Migu.docx
farrahkur54
 
Parthians- write one to two paragraphs on the significance of this ite.docx
farrahkur54
 
P(X-x).docx
farrahkur54
 
Overview You are required to prepare a Data Entry report which provide.docx
farrahkur54
 
package edu-ser222-m03_02- --- - A binary search tree based impleme.docx
farrahkur54
 
P(A)+P(A)-1 is one way to express the P(A)+P(A)-1 is one way to expres.docx
farrahkur54
 
P(Z-0-86).docx
farrahkur54
 
Overton Company has gathered the following information-Compute equival.docx
farrahkur54
 
Over 1 million Americans make a living working for advertising and pub.docx
farrahkur54
 
Oscar is suing John for $1000 dollars but the judge sees that their ar.docx
farrahkur54
 
Organizational Behavior Chapter 5 - Perception and Indigidual Decision.docx
farrahkur54
 
ook at the mean- median- mode- and standard deviation and describe how.docx
farrahkur54
 
Option #1- Creating a GUI Bank Balance Application Create a simple Gr.docx
farrahkur54
 
Operational Metrics and Benchmarking in Healthcare- What are common op.docx
farrahkur54
 
One of the duties and functions of the joint OHS committee is to ensur.docx
farrahkur54
 
One of the deadliest heart conditions is a disturbance in heart rhythm.docx
farrahkur54
 
Once you have all the structures working as intended- it is time to co.docx
farrahkur54
 

Recently uploaded (20)

PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PPT
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
PPTX
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PPTX
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
PDF
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PDF
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
PDF
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
Arihant Class 10 All in One Maths full pdf
sajal kumar
 

Option #1- Form Validation in JavaScript 1- In your text editor- open.docx

  • 1. Option #1: Form Validation in JavaScript 1. In your text editor, open the index.htm file from the HandsOnProject6-1 folder in the Chapter06 folder , add your name and today's date where indicated in the comment section, and then save the file. 2. Create a new document in your editor, add JavaScript comments containing the text Hands-on Project6-1, your name, and today's date, and then save the file to the HandsOnProject6-1 folder with the name script.js. 3. Return to the htm file in your browser, within the body section, just before the closing /body tag, add a script element, and then specify the file script.js as the source. 4. In the opening form tag, add code to disable browser-based validation, and then save your changes. 5. In the script.js file, add code instructing processors to interpret the contents in strict mode, and then create a global variable named formValidity and set its value to true. 6. Add the following function to validate the required form elements: 7. Add the following function to create an event lister for the submit event. 8. Add the following function to trigger validation of required fields when the Submit button is clicked: 9. Add the following code to call the createEventListeners() function when the page finishes loading. 1 /* run setup functions when page finishes loading */ 2 if (window.addEventListner) { 3 window.addEventListner("load", createEventListenres, false); 4 } else if (window.attachEvent) { 5 window.attachEvent ("onload", createEventListeners); 6 } 10. Save your changes to script.js, open index.htm in a browser, and then test various combinations of invalid and valid data to ensure that the scripts you wrote behave as you expect. Debug your code as necessary until it functions correctly. 11. Returntoscript.js in your editor, and then add the following function to validate input elements with the number type: 1/ validate number fields for older browsers % 2 function validate Numbers () { 3 var numberInputs = document.querySelectorAll (H"#contactinfo input[type=number]"); 4 var elementCount = numberInputs.length; 5 var numErrorDiv = document.getElementByld("numErrorText"); 6 var numbersValidity = true; 7 var currentElement; 8 try { 12. In the validateForm() function, add a call to the validateNumbers() function as follows: 13. Save your changes to script.js, open index.htm in a browser, and then test various combinations of invalid and valid data, including nonnumeric entries in number fields, to ensure that the scripts you wrote behave as you expect. Debug your code as necessary until it functions correctly.