Nick LaMarca
Nick LaMarca

Reputation: 8188

Getting Checkbox Value Jquery Mobile

I am setting my jquery mobile checkboxes like so..

 $("#checkbox-2a").attr("checked", settings.DEnabled).checkboxradio("refresh");

Here is the markup

 <fieldset data-role="controlgroup" data-mini="true" style="text-align:center;">
            <input type="checkbox" name="checkbox-2a" id="checkbox-2a" class="custom" />
            <label for="checkbox-2a">
                Enable D</label>
..

The checkboxes get checked correctly. But now when I want to retrieve a value with this code..

  settings.DEnabled = $("#checkbox-2a").attr("checked");

When I debug it returns 'checked', when I look at the markup eventhough the checkboxes are getting updated when the correct check bool in the ui. I dont see a 'checked' attribute in the markup.

How do I get/find the value of the checkbox?

Upvotes: 7

Views: 14267

Answers (1)

Ram
Ram

Reputation: 144679

attr doesn't return a boolean value, you can use prop method: http://api.jquery.com/prop/#entry-examples

settings.DEnabled = $("#checkbox-2a").prop("checked");

Or is method:

settings.DEnabled = $("#checkbox-2a").is(":checked");

Upvotes: 16

Related Questions