3

I´m trying to change the checkbox status (checked / unchecked) using JQM.

In the HTML part i have a checkbox, a button Clear and a button Set.

In the Java Script part i have the code to clear and to set the checkbox "checked" value using the buttons

 HTML code piece:
 ----------------
 <label><input type="checkbox" name="checkboxName" id="checkboxID">checkbox</label>
 <a href="#" id="clear" data-role="button" data-inline="true" data-theme="b">Clear</a>
 <a href="#" id="set" data-role="button" data-inline="true" data-theme="b">Set</a>

 JS code piece:
 --------------
 $("#clear").click(function() {
    $('#checkboxID').filter(':checkbox').prop('checked',false);
 });

 $("#set").click(function() {
    $('#checkboxID').filter(':checkbox').prop('checked',true);
 });

Check this example in: http://jsfiddle.net/VXwzp/14/

You will notice by hitting the button Set or Clear it is not working.

I´m using Google Chrome Version 26.0.1410.64 m

I have noticed, in case i remove the tag from input it works fine but the JQM style is not being taken into account.

 <input type="checkbox" name="checkboxName" id="checkboxID">

Check the example in: http://jsfiddle.net/QLzBX/1/

Do you have any idea how to get it work using JQM?

Thank you in advance

Alvaro

1
  • By using the following i was able to get it working: $('#checkboxID').attr("checked",false).checkboxradio("refresh"); Commented May 10, 2013 at 17:10

1 Answer 1

6

Working example: http://jsfiddle.net/Gajotres/VXwzp/15/

$("#clear").click(function() {
    $('#checkboxID').filter(':checkbox').prop('checked',false).checkboxradio("refresh");
});

$("#set").click(function() {
    $('#checkboxID').filter(':checkbox').prop('checked',true).checkboxradio("refresh");
});

When working with jQuery Mobile you must understand how its widgets markup can be changed, to find out take a look at my other answer: jQuery Mobile: Markup Enhancement of dynamically added content

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.