mardi 24 octobre 2017

Laravel getting value of checkbox in ajax Error :Cannot read property 'checked' of null

I am showing the checkbox value checked or unchecked based on the db value.but when user try to change it like unchecked it and update the value. i call the ajax i getting this error.

Thanx for help Code

 <div class="">
        <a>
          
           <i class="fa fa-id-card"></i> 
            <span>Employee</span>
        </a>
    </div>

Below is the Ajax Function

$(document).ready(function(){
   $('#customize').click(function(e){
        e.preventDefault();
      var customers=document.getElementById('customers').checked ? '1' :'0' ;
      var accounts=document.getElementById('accounts').checked ? '1' :'0';
      var Inventory=document.getElementById('InventoryItems').checked ? '1' :'0';
      var Employee=document.getElementsByName('Employee').checked ? '1' :'0'; 
       console.log(Employee);

       $.ajaxSetup({
            headers: {
              'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

       $.ajax({
           url :"",
           type :'POST',
           data :{

              customer : customers,
              accounts : accounts,
              inventory: Inventory,
              employee : Employee
           },
           dataType: 'JSON'
         //   ,
         // success: function( data ) {
         //    $("#ajaxResponse").append(data.msg);
         //    console.log(data);
        //}  

       });   
   });
});




Aucun commentaire:

Enregistrer un commentaire