Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 671
Nick LaMarca Avatar asked Sep 12 '12 16:09

Nick LaMarca


1 Answers

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");
like image 158
undefined Avatar answered Oct 19 '22 05:10

undefined