开发者

jquery validate for non disabled items

开发者 https://www.devze.com 2023-04-05 23:07 出处:网络
I have a form which has some inputs which are sometimes disabled (meaning, if the user answers certain questions, new input boxes will then become enabled.) I am trying to create a jquery code that wi

I have a form which has some inputs which are sometimes disabled (meaning, if the user answers certain questions, new input boxes will then become enabled.) I am trying to create a jquery code that will check for all of the non-disabled entrys from being blank. At the moment, I tried the following and it didn't work:

$(document).ready(function(){   
    $('submit').click(function()
    {
        if( $(':text:not(:disabled)').val().l开发者_运维知识库ength === 0) 
        {
            $('#message').html('All Entries Must Be Completed');

        }
    });                                     
});

Can someone help me?


Since this line:

$(':text:not(:disabled)')

Will return multiple items (an Array) you would need to loop over each one and check to see if it is empty using .val().

Or modify your selector to get only those that are disabled AND empty.

$(document).ready(function(){   
    $('input[type=submit]').click(function(e) {
            if( $(":text:not(:disabled)[value='']").length != 0) {
                    alert('All Entries Must Be Completed');
                    return false;
            }
    });                                     
});
0

精彩评论

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