ritacse
4/24/2017 - 11:52 AM

All about checkbox & Radio button

On checkbox select read data from table


 // ------- we use this -----// 
 
 $('#chkSelectAll').change(function () {
        if ($("#chkSelectAll").is(':checked'))
            $('._rowChkBox').attr('checked', this.checked);   //.attr or .prop both can be used
        else
            $('._rowChkBox').removeAttr('checked');
    });
    
    
    
      $("._rowChkBox").click(function () {
        if ($("#ckAllEmployee").is(':checked')) {
            $('#ckAllEmployee').removeAttr('checked');
       
            $.uniform.update();

        }
    });
    
    
    var checkedCount = $('._rowChkBox:checked').length;
    
  //  radioButton value
    $('input[name=rdbStatus]:checked').val();  //get
    
     //set
    $("input:radio[name=rbdStatus][value=1]").attr('checked', 'checked');    
     $("input[name=rdbStatus][value=" + value + "]").attr('checked', 'checked');
     
     $('#rdbSupplier').prop('checked', true)
     
   //  check box value
    $('#_rowChkBox:checked').val();           //get
    $('#chkNewBatch').attr('checked',false);  //set
    $("#chkSelectAll").is(':checked')         // if condition

/// ========= in HTML Table  ==========
function SelectAll(e) {
       //---value read from multiple checkboxes
//$('input[name="locationthemes"]:checked').each(function() {
 //  console.log(this.value); 
//});
////----- OR     
       
    $(e).closest('table').find('td input:checkbox').prop('checked', e.checked);
    
    ReadNotifyList = [];
    if (e.checked) {
        $.each(PendingNotificationQueue, function (index, value) {            
            var objAdd = {
                "ID": value.ID
            }
            ReadNotifyList.push(objAdd);
        });
    } 
}

/// ========= in JQuery DataTable  ==========

 // Handle click on "Select all" control
    $('#ckbSelectAll').on('click', function () {
        ReadNotifyList = [];
        // Check/uncheck all checkboxes in the table
        var table = $('#tblPendingNotigication').DataTable();
        var rows = table.rows({ 'search': 'applied' }).nodes();        
        $('input[type="checkbox"]', rows).prop('checked', this.checked);

        // Get Checked value
        if ($('#ckbSelectAll').is(":checked")) {
            $.each(PendingNotificationQueue, function (index, value) {
                var objAdd = {
                    "ID": value.ID
                }
                ReadNotifyList.push(objAdd);
            });
        }
    });