Sachith Sachith - 5 months ago 23
Javascript Question

How to populate checkboxes using JavaScript in Laravel 5.2

I want to populate a list of check boxes dynamically using JavaScript. I have done the 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>


My script:

var itemID=;

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

passes wanted data.

I want my view to be like this, a checkbox followed by Names:

Expected result

But what I'm getting is this:

Actual result

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


Try this :

$('#demos').append('<input type="checkbox" value="' + subcatlist[0].ID + '"/>' + subcatlist[0].Name);

I think this will solve the problem.