using toggle to save login with local storage

69 views
Skip to first unread message

saroy

unread,
Jan 27, 2012, 6:36:34 AM1/27/12
to iPhoneWebDev
hi all

i would like to use toggle to save login with local storage (toggle
off = onclick save to local storage, toggle on = onclick remove
localstorage)

i used to function for this :

for add :

function add() {
window.localStorage.setItem("compte",
document.getElementById('txtNum_Compte').value);
window.localStorage.setItem("acces",
document.getElementById('txtCode_Accer').value);
}

for remove :

function remove() {
window.localStorage.removeItem("compte");
window.localStorage.removeItem("acces");
}

and this function on body load page to get localstorage

function getcompte() {
if (localStorage.getItem("txtNum_Compte") != "")
{ document.getElementById('txtNum_Compte').value =
window.localStorage.getItem("compte");
document.getElementById('txtCode_Accer').value =
window.localStorage.getItem("acces");

}

how can i attribute this function to onclick toogle to get run

and how can save toogle state

thanks in advance and sorry for my bad english

Remi Grumeau

unread,
Feb 9, 2012, 10:09:01 AM2/9/12
to iphone...@googlegroups.com
I love those frenglish function names :)

For the moment, toggle is just a div element with 3 spans in it. It's not a form element like a select or input checkbox. So the only way to get toogle state is to check if its has an attribute "toggled" to true.

ex: if your toggle element has an id attribute to 'myToggle'
<div class="toggle" toggled="true" id="myToggle">
<span class="thumb"></span>
<span class="toggleOn">ON</span>
<span class="toggleOff">OFF</span>
</div> 

Then, to get its state during form check process, look at its "toggled" attribute value:
var toggleState = (document.getElementById('myToggle').getAttribute('toggled')=="true")?true:false;

Depends on your needs, but you can also put an onclick event on the toggle itself:
<div class="toggle" toggled="true" id="myToggleonclick="alert(this.getAttribute('toggled'))">
<span class="thumb"></span>
<span class="toggleOn">ON</span>
<span class="toggleOff">OFF</span>
</div>

Hope this help!

Remi



--
You received this message because you are subscribed to the Google Groups "iPhoneWebDev" group.
To post to this group, send email to iphone...@googlegroups.com.
To unsubscribe from this group, send email to iphonewebdev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/iphonewebdev?hl=en.


Mogens Beltoft

unread,
Feb 9, 2012, 1:22:14 PM2/9/12
to iphone...@googlegroups.com
Hi,

What toggle are you referring to?

If it's a checkbox, then have a look at this page:
http://www.javascriptkit.com/jsref/checkbox.shtml

If you use the onclick event you need to find the state of your toggling
object to determine whether to call add() or remove().

/Mogens

Mogens Beltoft

unread,
Feb 9, 2012, 1:23:42 PM2/9/12
to iphone...@googlegroups.com
Oh, sorry - I forgot about the toggle in iUI...

Have a look at this:
http://groups.google.com/group/iphonewebdev/browse_thread/thread/c2e40f540da9209c?pli=1

/Mogens

On 27-01-2012 12:36, saroy wrote:

Reply all
Reply to author
Forward
0 new messages