简体   繁体   中英

Why my form doesn't validate the fields?

I can't see a clear mistake in this code. Instead of validating my fields, it just tries to send my form and I don't know why.

This is my jsFiddle: http://jsfiddle.net/PAALA/

Other question, how to validate if select box was picked?

Firstly, because of how JSFiddle works, defining a function with function foo() {...} is unreliable. Instead, use foo = function() {...} syntax.

Next, you have an error in your script when you try to access document.forms["bug_form"]["Project"].value - there is no text input with that name.

Finally, to prevent accidental submission, do this:

validateBugForm = function() {
    try {
        // ALL YOUR ORIGINAL CODE HERE
    }
    catch(e) {
        alert("An error occurred: "+e);
        return false;
    }
}

This will ensure that false is returned, even if your code errs.

The Javascript code is crashing out on the third line when you try to get the value for "Project". Looks like you forgot to give that one a name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM