William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

jQuery: Is checkbox checked?

jQuery: Is checkbox checked?

for checkbox, radio, or select menu, sometimes we need to judge which one(s) is/are selected. Here I use checkbox as example, list 2 very common ways to check if they are checked or not?


// 1. use filtering is() and :checked Selector.
if($('#checkboxs_id').is(':checked')){...}

// 2. use checkbox attribute 'checked'.
if ($('#checkBox').attr('checked')) {...}

The following is the checkbox interaction between jQuery and PHP codes:

// 1. use jQuery to get the checkbox group values.
$('input[name="mycheckboxes"]:checked')
  .map(function(){ return $(this).val(); })
   .get().join(",");
// 2. Then explode in PHP:
$mycheckboxes = explode(',',$_GET['mycheckboxes']);
Advertisements

One response to “jQuery: Is checkbox checked?

  1. powercashadvance.com 10/26/2011 at 3:50 pm

    It was some sort of pleasure locating your site this morning. I arrived here just now hoping to find out new things. I was not dissatisfied. Your ideas about new strategies on this area were insightful and an excellent help to my family. Thank you for having time to write down these things along with sharing your thinking.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: