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 trialQuillor Studio
7,658 PointsHow to disable Submit form?
HI,
I am wrapping up this Jquery Project and I'm running into problems: http://teamtreehouse.com/library/jquery-basics/creating-a-password-confirmation-form/perfect
I am trying to disable the Submit Form if the user does not provide correct information.
But the user is still able to send a form, even if the form is incorrect.
Here is my project: http://quillor.com/treehouse/jqueryform/
Here is my js code: http://quillor.com/treehouse/jqueryform/js/app.js
Does anyone have an idea what is going on?
2 Answers
Jason Anello
Courses Plus Student 94,610 PointsHi Tim,
Your submit button is missing the id id="submit"
You have in your html:
<input type="submit" value="SUBMIT">
Should be:
<input id="submit" type="submit" value="SUBMIT">
The enableSubmitEvent
function depends on this id
being there in order to disable/enable the submit button.
James Andrews
7,245 PointsIf your form hits the error conditional you want to return false this will keep the form from submitting.
jQuery('#myformid').submit(function(){
if(error)
{
return false;
}
return true;
});
James Andrews
7,245 PointsJames Andrews
7,245 Pointsthe thing that is poor about his solution is all someone has to do is hit the enter/return key and the form will submit automatically. He has to watch for the actual submit event and stop return false if it's not ready to go.
Quillor Studio
7,658 PointsQuillor Studio
7,658 PointsThanks Jason Anello ! that was it.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsYou're welcome Tim.
James,
This project has code to disable the submit button if the proper conditions aren't met. Once the proper conditions are met then the submit button is enabled. It doesn't use jQuery's
.submit()
method.