1

I'm trying to change the state of my jQuery Mobile checkboxes using the following code:

$('#_inputcb_Q801').prop('checked', false);

I also found the following solution on jQuery Mobile:

$('#_inputcb_Q801').prop('checked', false).checkboxradio('refresh');

but it gives this error:

Runtime-error Microsoft JScript: cannot call methods on checkboxradio prior to initialization; attempted to call method 'refresh'

How can I solve the problem ?

SharpC
  • 6,974
  • 4
  • 45
  • 40
user1652050
  • 153
  • 3
  • 6
  • 16
  • 1
    The error message seems to be pretty indicative of the issue. Most likely the like calling the refresh is loaded before the plugin is bound to the element `$('#_inputcb_Q801').checkbox()`. Just make sure you are not calling the refresh before you initialize the plugin on the element. – Bogdan Nov 15 '12 at 13:59
  • I found this method worked for me: https://stackoverflow.com/questions/17027566/how-to-check-checkbox-dynamically-jquery-mobile#67749920 – SharpC May 30 '21 at 10:58

3 Answers3

3

try it.

  • checkbox

    $('.ui-checkbox input').attr('checked', false).checkboxradio('refresh');

  • selectbox

    $('.ui-select select').val('').selectmenu('refresh');

Sirko
  • 72,589
  • 19
  • 149
  • 183
kien
  • 31
  • 2
0

found the solution, ill post it below it might help someone:

  $('#_bQ801').click(function(){
        $.mobile.changePage('#Question_09_01', 'slide', false, false);
        $('#_inputcb_Q901').attr('checked', false);
        $('#_inputcb_Q901').checkboxradio('refresh');}
user1652050
  • 153
  • 3
  • 6
  • 16
  • Improvement: remove click-handler, remove $.mobile... Only the last two statements are required. – Zim84 Jul 23 '13 at 08:23
-1

try this

$('#_inputcb_Q801').attr('checked', false);
c-sharp
  • 573
  • 1
  • 9
  • 25
  • thanks for your reply, it works but it doesnt update the user view, in code it's unchecked but the user still sees the checkbox as checked. – user1652050 Nov 15 '12 at 14:09
  • I think it will update view too. Try it $('#_inputcb_Q801').change(); – c-sharp Nov 15 '12 at 14:30
  • The problem with this solution is that it does update the underlying checkbox, but as user1652050 mentioned, it does not update the enhanced code made by jQuerymobile. You have to update it as well. – Zim84 Jul 23 '13 at 08:45