Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
41
rated 0 times [  42] [ 1]  / answers: 1 / hits: 28621  / 13 Years ago, tue, february 14, 2012, 12:00:00

I have some jQuery Mobile flip toggle switches on my Android/iPad application, and I need to
change their states (on/off) dynamically, using JavaScript.
I was looking for a solution here, (Change value of flip toggle dynamically with jQuery Mobile) and I tried several ways (.val('on'), .slider('enable')...) but it seems the control is not working at all.



Is there a solution for this issue? How can I do to change the flip switch state from code?


More From » jquery

 Answers
9

I've examined the page you posted and I confirmed that the solution:



$('selector').val('value').slider('refresh');


does indeed work. Make sure that 'selector' is referencing your select element, and that 'value' is a value you defined on the option element you wish to enable.



I confirmed this by visiting http://jquerymobile.com/demos/1.0.1/docs/forms/switch/index.html, then with firebug's console entering the line:



$(#flip-b).val('no').slider('refresh');


It switched the second slider displayed on the page from yes to no.


[#87458] Tuesday, February 14, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devinjadong

Total Points: 711
Total Questions: 117
Total Answers: 100

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
devinjadong questions
Thu, Feb 17, 22, 00:00, 2 Years ago
Wed, Dec 8, 21, 00:00, 2 Years ago
Tue, Oct 27, 20, 00:00, 4 Years ago
Fri, Oct 18, 19, 00:00, 5 Years ago
;