• Blogs (9)
    • 📱 236 - 992 - 3846

      📧 jxjwilliam@gmail.com

    • Version: ‍🚀 1.1.0
  • jQuery: Is checkbox checked?

    Blogs20112011-10-10


    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']);