DCJones
DCJones

Reputation: 3451

Populating a input checkbox with the result of an Ajax call

I need to set the value of a Bootstrap checkbox based on the value returned be an Ajax call.

My checkbox code:

<input type="checkbox" name="EditDisplayOneLineText" id="EditDisplayOneLineText"value=""  class="btn btn-xs" checked data-toggle="toggle" data-size="mini" data-onstyle="info" data-offstyle="default">

My jQuery:

var dt = result[22];
if (dt == 1) {
  $('#EditDisplayOneLineText').is(':checked');
}

Where am I going wrong?

Upvotes: 1

Views: 48

Answers (1)

j08691
j08691

Reputation: 207891

You should be setting the checked property to true like:

$('#EditDisplayOneLineText').prop('checked', true);

Properties generally affect the dynamic state of a DOM element without changing the serialized HTML attribute. Examples include the value property of input elements, the disabled property of inputs and buttons, or the checked property of a checkbox.

Upvotes: 3

Related Questions