dale
Posts: 0
Joined: Fri Mar 29, 2013 5:28 pm

Getting if a toggle is checked and set to local variable.

I have a toggle button, and when the value is changed, I wish to set a local variable.
The toggle is called mobiletoggle1_33.
I'm always get an 'undefined' in the console.log.
I wouldn't usually ask for support as I'm learning, but after a fair few hours it's driving me crazy.

I have set an event for the toggle, onchange, and run javascript.

var meme= Tiggzi('mobiletoggle1_33').attr("checked");
console.log(meme);
localStorage.setItem('dealprom', meme);

var me=localStorage.getItem('dealprom');
console.log(me);

Ta.

Dale.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Getting if a toggle is checked and set to local variable.

Hello! The toggle button in fact is a Select (see documentation here http://jquerymobile.com/demos/1.2.0/d...). So you would need to get value like from select:
instead of this line codevar meme= Tiggzi('mobiletoggle1_33').attr("checked"); /code use the following codevar meme= Tiggzi('mobiletoggle1_33').val();/code

dale
Posts: 0
Joined: Fri Mar 29, 2013 5:28 pm

Getting if a toggle is checked and set to local variable.

Oh! Haha, silly me ... must admit, wouldn't have thought of that, thought it was like a checkbox.
Thankyou.
Great support as always.
Dale.

Return to “Issues”