开发者

Problem with jquery code checkbox values takes as undefined

In the code shown below.... it should be able to fetch only the checkbox which is checked.. but it is taking the value as undefined....what is the problem in the code... and it displays all the checked and unchecked checbox table row contents

       for(k=1;k<=9000;k++)
        {   //each change
     $("#status"+k).live('click', function () {
        for(j=1;j<=k;j++)
     {
        alert (j);
            //var stat开发者_运维技巧us = $("input[name=status]:checked").val();
                                            //alert(status);
            if ($('#status:checked').val() !== undefined) { 
                                            alert("false"); 
            var product_name = encodeURIComponent($('#product_name'+j).val());      
            var barcode = encodeURIComponent($('#barcode'+j).val());
            var Quantity = encodeURIComponent($('#Quantity'+j).val());
            var cart=product_name + barcode + Quantity;
                    alert(cart);
                        } else {
                    alert("true");  
            } 

        $('#cart1').val(cart);  
     }

    });

}   


if ($('#status').is(':checked')) {


Try this:

if($(this).is(':checked')) {

In place of: if ($('#status:checked').val() !== undefined) {

I also suggest you to use jQuery .delegate() to get rid of that loop. http://api.jquery.com/delegate/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜