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 jQuery Basics (2014) Introduction to jQuery Include jQuery in a Project

Quillor Studio
Quillor Studio
7,658 Points

How 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

Hi 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.

the 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.

You'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.

If 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;
});