From the course: Validating and Processing Forms with JavaScript and PHP
Unlock this course with a free trial
Join today to access over 22,400 courses taught by industry experts.
Accessing forms
From the course: Validating and Processing Forms with JavaScript and PHP
Accessing forms
Accessing forms is similar to accessing other HTML elements but because of their nature there are some additional methods and properties we can take advantage of. If you'e given your form an ID, the easiest way to have access to the form element is by using getElementById, but with forms, you can also look up elements by name. So here's a form I've created with a number of different types of fields. If you're interested in how this form was put together, make sure you check out my course on CSS styling forms. I put together this form on chapter six. So I'm using the Google Chrome browser and I need to look at the Developer tools. I'm going to right click on this form and select Inspect Element from the pop up menu. From here, I need to go to the JavaScript Console which is the last tab. Now let's add some code to send the form information to the JavaScript Console. This form has an ID of my forms, that's what I'll type in here. So we were successfully able to target the form itself…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Accessing forms3m 57s
-
Looking up form elements3m 35s
-
Handling focus changes2m 47s
-
Detecting the onchange event4m 31s
-
Using the selectedIndex property2m 30s
-
Dynamic validation with regular expressions7m
-
Creating a generic input validation function4m 31s
-
Validating in older browsers with Modernizr7m 32s
-
Interrupting form submission with onsubmit5m 50s
-
-
-
-
-