Checking and unchecking radio buttons with Jquery Mobile
Asked Answered
Y

5

9

I can't check a set of checkboxes programatically with jquery mobile, I have the following code:

<div data-role="fieldcontain"  id="div_radio" class="radiogroup">
    <fieldset data-role="controlgroup">
        <input type="radio" name="radio-pieces" id="radio-choice-1" value="3" checked="checked" />
        <label for="radio-choice-1">1 to 3</label>

        <input type="radio" name="radio-pieces" id="radio-choice-2" value="5"  />
        <label for="radio-choice-2">4 to 5</label>

        <input type="radio" name="radio-pieces" id="radio-choice-3" value="6"  />
        <label for="radio-choice-3">over 5</label>
    </fieldset>
</div>

If I do: $("input[type='radio']:last").attr("checked",true).checkboxradio("refresh"); everything works perfect, but none of this work at all:

$("input[type='radio']:first").attr("checked",true).checkboxradio("refresh");
$("input[type='radio']:eq(0)").attr("checked",true).checkboxradio("refresh");
$("input[type='radio']:eq(1)").attr("checked",true).checkboxradio("refresh");
$("input[type='radio']:eq(2)").attr("checked",true).checkboxradio("refresh");

How can I properly manipulate these elements? Unselecting all checkboxes also works fine:

$("input[type='radio']").attr("checked",false).checkboxradio("refresh");

It seems that the only checkbox working is the last one.

Yen answered 18/1, 2013 at 23:57 Comment(0)
B
24

They all work just fine. You just need to trigger refresh on all input radio in group.

$("input[type='radio']:first").attr("checked", "checked");
$("input[type='radio']").checkboxradio("refresh");

jsFiddle is here.

Blase answered 19/1, 2013 at 3:34 Comment(0)
C
5

Nothing worked for me except:

$('#reset').click(function(){
    $('#Store').trigger("click").trigger("click"); // yes... twice
});

On jQuery Mobile 1.4.2.

Contumely answered 29/6, 2014 at 21:40 Comment(0)
G
1

For me works this to uncheck the whole group of radios:

$(".my_class").removeAttr("checked");
$(".my_class").checkboxradio("refresh");
Generality answered 24/5, 2015 at 13:57 Comment(0)
P
0

This doesn't seem right. The single quote is not needed input[type=radio] is correct. I'm using an outdated version (1.1.1). It would be help to know what version you're using.

Keep in mind that those are radio buttons, only one selected at a time.

Parthen answered 19/1, 2013 at 0:48 Comment(0)
C
0

in Jquery mobile radio button refresh like this:

$(".iscfieldset input[type='radio']:first").attr("checked", "checked");


    $(".iscfieldset input[type='radio']").checkboxradio().checkboxradio("refresh"); 

try this working fine for me

Crave answered 8/4, 2014 at 8:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.