开发者

jQuery process groups of checkboxes

So I have several groups of checkboxes that are all related. More specifically, it is a permission system. Each user group has their set of permissions, so Admin gets view/read/create, Member gets view/read/create, and so on. Each group will have checkboxes for each permission, so as to select which groups can do what.

Processing with PHP is cake, can just do name="permission[$group_id][]" and that's pretty much it. However being not very fluent with Javascript, I'm having a bit of trouble processing it with jQuery in the same fashion. Ultimately I need to be able to pass the checkboxes to a PHP script with AJAX. I also have to be ab开发者_运维问答le to populate the checkboxes with AJAX/Javascript.

Any pointers appreciated.


Just do this:

$.ajax({
   ...
   //Select all checkboxes whose names begin with 'permission[', and serialize them for correct ajax transport
   data: $(":checkbox[name^='permission[']").serialize()
   ...
});

It will encode your checkboxes name automagically.


First you can select your checkboxes by name to find which have been checked, something like:
$('input[name=yourname]:checked').val();
http://api.jquery.com/val/

to get your values and loop them into an array,
or you can 'serialize' your form:
http://api.jquery.com/serialize

then you can submit your data via post with:
http://api.jquery.com/jQuery.post/

Hope this helps. If you post some code I can give you more direct support.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜