mardi 13 septembre 2016

how to populate checkboxes using javascrip in Laravel 5.2

I want to populate a list of check boxes dynamically using javascript.
I did following.
In my balde view

<div  id="demo" class="collapse" > 
    <div class="panel panel-default" >
          <div class="panel-body" id="demos" style="max-height: 100px;overflow-y: scroll;" >

             <input type="checkbox" name="specific[]" value=" "> <br>

           </div>    
     </div>
 </div>

My script

$(document).ready(function(){
     $('#ItemID').on('change',function(e){
        console.log(e);
        var itemID= e.target.value;


        $.getJSON('/xxxxx/list?itemID=' + itemID, function(data){
           $('#demos').empty();
           $.each(data,function(index, subcatlist){
               $('#demos').append('<input value="'+subcatlist[0].ID+'">'+subcatlist[0].Name+'</input>');
            });
          });             
        });
      });

route.php passes wanted data to here.
I want my view to be like this,checkbox followed by Names
Expected result

But what I get is this
Actual result

I am getting Names to the view, but leading check box is missing and replaced with a textbox.
How to fix this problem?
Thanks in advance




Aucun commentaire:

Enregistrer un commentaire