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

HTML

Andrew Young
PLUS
Andrew Young
Courses Plus Student 639 Points

Form can't submit again after onsubmit return false

So I have the following code

function submitform() {
    console.log("run");
    var pwd1 = $("#password").val(),
        pwd2 = $("#passwordc").val(),
        errplace = $("#pwderror");
    if (pwd1 != pwd2) {
        errplace.html('<div class="alert alert-danger alert-dismissible fade show" role="alert"><strong>Error!</strong> 兩個密碼不相符<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
        return false;
    } else {
        return true;
    }
}

which will be called while form submitting by onsubmit='return submitform()', but after I failed once (password wrong), and the functio return false. The form can't be submit anymore whether pressing ENTER key or submit button. How to fix this?

1 Answer

Steven Parker
Steven Parker
229,732 Points

I wasn't able to replicate the issue, it seems to work OK.

I had to guess at the rest of the code, perhaps the actual code is different in a way that might explain the issue.