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

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…

Contents