1

I try to set button radio by calling ajax (fill up form by request database in php).
I use $('input:radio[name="radio_animal"]').filter('[value="cat"]').prop('checked', true);
Note : It’s works good for all input by $(‘#name’).val(‘lastname ’); but nothing else for button radio.

Please help me
Do the test online on : http://jsfiddle.net/Brolosse/BUBtL/

Check my code :

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.css" />
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.js"></script>    
<input id="input_text" type="text">
<fieldset data-role="controlgroup" id="field_radio_amis">
    <legend></legend>    
    <label for="cat">Cat</label>
    <input type="radio" name="radio_animal" id="cat" class="custom" value="cat" />    
    <label for="dog">Dog</label>
    <input type="radio" name="radio_animal" id="dog" class="custom" value="dog" />    
</fieldset>
<input type="button" name="btn_go" id="btn_go" value="Click to set button radio and inputbox" />

$(document).ready(function () {
    $("#btn_go").click(function () {
        $('#input_text').val('It\'s OK ! but no radio check')
        $('input:radio[name="radio_animal"]').filter('[value="cat"]').prop('checked', true);
    });
    return false;
});
Omar
  • 32,302
  • 9
  • 69
  • 112
Brolosse
  • 39
  • 3
  • possible duplicate of [How to check "checkbox" dynamically - jQuery Mobile](http://stackoverflow.com/questions/17027566/how-to-check-checkbox-dynamically-jquery-mobile) – Omar Jan 23 '14 at 12:14

1 Answers1

0

If you call checkboxradio("refresh"); it will be rendered correctly.

http://jsfiddle.net/YdT5f/

$(document).ready(function () {

    $("#btn_go").click(function () {
        $('#input_text').val('It\'s OK ! The radio looks good :)')
        $('input:radio[name="radio_animal"]').filter('[value="cat"]').prop('checked', true).checkboxradio("refresh");
    });

    return false;

});
Community
  • 1
  • 1
melc
  • 11,523
  • 3
  • 36
  • 41
  • oooooooooooooooooooh it works good oh thank you thank you oh really thank you for your help.I'am so happy now. you make my day. Andre – Brolosse Jan 23 '14 at 14:06
  • @Brolosse i'm glad it worked. Please mark the answer as accepted to assist other visitors as well, thanks. – melc Jan 23 '14 at 16:45