Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

How to validate a form with Javascript ?

I have a simple form that I'm trying to validate with javascript. The problem that I'm having is that the form gets sent as soon as you click on the submit button. How do I prevent the form being submitted on till validation is met ?

1 Answer

Create a validation function that will execute when the user clicks the submit button. In that function specify that if conditions are met then submit, else show an error message.