Validating and submitting the form using JavaScript
HTML Forms are the most important part of web applications, where user input is recorded. In our JS Meetup app, we got a nice looking form built with the help of Bootstrap. Let's explore what the form contains using the index.html
file. The form contains four compulsory fields:
Name
Email Address
Phone Number
Age
And it also contains three optional fields (two of whose values are preselected):
- The user's profession
- His experience level in JavaScript
- Comments on what he expects to learn from this event
Since profession and experience level options are preselected with a default value, they aren't marked as compulsory to the user. But, during validation, we need to consider them as compulsory fields. Only the comments field is optional.
Here's how our form should work:
- The user fills up all the form details and clicks
Submit
- The form details will be validated and if any required fields are missing, it will highlight the fields with a red border
- If the...