1D0-720 · Question #46
How can JavaScript be used for form validation?
The correct answer is C. By checking the values of form elements before submission. JavaScript validates forms by checking form element values before submission (C) - for example, verifying that a required field isn't empty, that an email matches a pattern, or that a password meets length requirements, all without requiring a round-trip to the server. Why the…
Question
How can JavaScript be used for form validation?
Options
- ABy changing the CSS of the form.
- BBy automatically submitting the form.
- CBy checking the values of form elements before submission.
- DBy linking the form to a database.
How the community answered
(35 responses)- A3% (1)
- B6% (2)
- C89% (31)
- D3% (1)
Explanation
JavaScript validates forms by checking form element values before submission (C) - for example, verifying that a required field isn't empty, that an email matches a pattern, or that a password meets length requirements, all without requiring a round-trip to the server.
Why the distractors are wrong:
- A - Changing CSS is styling, not validation; it can highlight errors visually but doesn't verify data.
- B - Auto-submitting a form is the opposite of validation; validation prevents submission when data is invalid.
- D - Database linking is a server-side concern (think SQL/backend), not something JavaScript does directly in the browser.
Memory tip: Think of JavaScript form validation as a bouncer at the door - it checks your credentials (form values) before you're allowed in (form submits). The bouncer doesn't redecorate the club (CSS) or call the manager (database); it just checks what you're carrying.
Topics
Community Discussion
No community discussion yet for this question.