开发者

jQuery validation and check all together

I make a jqu开发者_Go百科ery validation, problem is here that this part from code first(first click on button) check selectbox and second(second click on button) fields. how can it fix as that check all together with one click on button?

Exampel(see full code): http://jsfiddle.net/JfPaN/

$('.submit').submit(function () {
    if (required_selectbox() == false || required_valid() == false) {
        return false;
    }
});


Your problem is caused by Short-Circuit Evaluation on this line expression :

required_selectbox() == false || required_valid() == false

Javascript will not execute required_valid() if required_selectbox() returns false, since it already knows the result of the boolean expression as soon as the left side is true.

Here is one solution to your problem:

$('.submit').submit(function(){
    var passed = required_selectbox();
    passed = required_valid() && passed;
    if(!passed)
        return false;
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜