开发者

jQuery get values from selected checkboxes

First problem is that I do not know how to get the values of SPECIFC checkboxes when they are checked.

I need a function that will get the value of the selected checkboxes by checkbox ID or Name.

Th开发者_StackOverflowis is the code I have so far:

    $("#doStatus").click(function(){
    var Tuitting = $('textarea#tuitting').val();
    var F = $('input#Fb').val(); //checkboxes with ID Fb
    var T = $('input#Tw').val(); //checkboxes with ID Tw
$.get("<?echo $site['url'];?>modules/yobilab/tuitting_core/classes/doStatusBox.php", { tuitting: Tuitting, f: F, t: T });
 window.setTimeout('location.reload()', 1000);
return false;
});

Now the second problem is that both var F and var T may contain MORE than one values in an array..

Obviously when I use the ajax get functions the multiple values for both var F and var T are not passed at all. What is the problem..?

How do I pass multiple values in an array that will be then runed by the foreach on the doStatusBox.php page?

Please help me.


$("#doStatus").click(function() {
    var Tuitting = $('textarea#tuitting').val();
    var F = $('input[name="fb"] :selected').val();

   //You can give the name of checkbox and get the values of selected checkbox
   return false;
});


I'm answering based on an assumption: you need checked checkboxes to pass them via GET method to your doStatusBox.php script.

However, why would you go trough the trouble of finding which checkbox is checked if you can simply use the serialize() method and let jQuery do the job for you?

$("#doStatus").click(function()
{
    var serialized = $("#someFormHere").serialize() 
    // or, if you have your form elements within a div or another element 
    var serialized = $("#elementID :input").serialize();

    $.get("<?echo $site['url'];?>modules/yobilab/tuitting_core/classes/doStatusBox.php", serialized);
    window.setTimeout('location.reload()', 1000);

    return false;
});

However, is "#doStatus" a submit button submitting the form or something else? If it submits the form, bind the submit event to the form, not click event to the button submitting it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜