1 / 5

JavaScript Validation

JavaScript Validation. Making Decisions. IF statements can be used to make logical decisions IF statements require a CONDITION that is evaluated to TRUE or FALSE Conditions use conditional operators: >, <, >=, <=, ==, != intGrade = prompt('What is your grade?'); if ( intGrade <= 60) {

alida
Télécharger la présentation

JavaScript Validation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JavaScript Validation

  2. Making Decisions • IF statements can be used to make logical decisions • IF statements require a CONDITION that is evaluated to TRUE or FALSE • Conditions use conditional operators: >, <, >=, <=, ==, != intGrade = prompt('What is your grade?'); if (intGrade <= 60) { alert('You fail!'); } else { alert('You pass.'); }

  3. JavaScript and Forms • HTML Forms have a special usage in JavaScript IF you’ve given the elements a NAME attribute. • You could always just use the ID and getElementById() • To access a form with JavaScript, use: document.forms['FormName'] • To access an element inside that form, use: document.forms['FormName']['ElementName'] • There are some specialized ways (such as dropdown boxes, you should be able to find those and use them)

  4. How Form Validation May Look window.onload = startScripts; function startScripts() { varfrm = document.forms['contactForm']; frm.setAttribute('onsubmit', 'return validateForm()'); } function validateForm() { varfrm = document.forms['contactForm']; if (frm['firstName'].value == '') { alert('First Name cannot be blank! '); return false; } }

  5. Form Validation Possibilities • Validation can be rather lengthy when doing things such as email addresses or phone numbers (think about it!) • You will PROBABLY utilize someone else’s script when doing validation UNLESS • You have a specialized thing to validate • You cannot find a script that does exactly what you want • You loooooove JavaScript • We will utilize the script found here: http://www.javascript-coder.com/html-form/javascript-form-validation.phtml#download

More Related