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 trialDanielle Howard
4,402 PointsAlternative way of disabling the submit button?
Is this a valid alternative way of disabling the submit button?
function enableSubmitEvent() { if (canSubmit()) { $("#submit").prop("disabled", false); } }
The rest of my code is exactly the same as in the video.
Thanks
2 Answers
Sean T. Unwin
28,690 PointsYou're on the right track. However, the way you have it written currently would enable the button and since buttons are generally enabled by default this probably would not do anything at all. You still need a way to disable the button when canSubmit()
equals false.
A way to do this could be:
function enableSubmitEvent() {
if (!canSubmit()) {
$("#submit").prop("disabled", true);
} else {
$("#submit").prop("disabled", false);
}
}
The way shown in the video is obviously the shorter way.
eck
43,038 PointsIt is not a true alternative because you are only enabling the submit, but not disabling it. So if the user enters valid info into the form, submit is enabled. If they then change something and the form is no longer valid they can still submit it.
This is a working alternative:
function enableSubmitEvent() {
if (canSubmit()) {
$("#submit").prop("disabled", false);
} else {
$("#submit").prop("disabled", true);
}
}
There is more code here though, so I would say Andrew's code in the video is the slightly better way of doing it.
Matthias NΓΆrr
8,614 PointsSo to clarify
("disabled", false)
just means: submit button is enabled ?!
eck
43,038 Pointseck
43,038 Pointsaw man, I am too slow! >.<
Sean T. Unwin
28,690 PointsSean T. Unwin
28,690 PointsHaha! That's happened so many times to me, too.