Friday, 15 January 2010

html5 - Variables stored in localstorage disappears when the page is refreshed -


This is a webpage where you can choose your background image with three radio buttons. I want to save the chosen one in the local storage, so when the page refreshes the last selected background image. This is not the case and I do not understand, why do you do it? Thanks in advance :)

  & lt ;! DOCTYPE html & gt; & Lt; Html manifest = "my.manifest" & gt; & Lt; Top & gt; & Lt; Script src = "modernizr.js" & gt; & Lt; / Script & gt; & Lt; Script & gt; Function SetBug () {myForm = document.getElementById ("bgList"); For (var i = 0; i  & Lt; Input type = "radio" name = "land" value = "news", onClick = "setBg ()" & gt; Norgay & lt; / Input & gt; & Lt; Input type = "radio" name = "land" value = "sverige.png" onClick = "setBg ()" & gt; Sverige & lt; / Input & gt; & Lt; Input type = "radio" name = "land" value = "danmark.png" onClick = "setBg ()" & gt; Denmark & ​​lt; / Input & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;    

I do not understand which part does not work? The warning displays the selected option properly, but when you are alerting before setting the background, there is no background style at the time of the alert, when you press the warning that the image is set correctly.

  & lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Script src = "http://modernizr.com/downloads/modernizr-latest.js" & gt; & Lt; / Script & gt; & Lt; Script & gt; Function SetBug () {myForm = document.getElementById ("bgList"); For (var i = 0; i  & Lt; Input type = "radio" name = "land" value = "news", onClick = "setBg ()" & gt; Norgay & lt; / Input & gt; & Lt; Input type = "radio" name = "land" value = "sverige.png" onClick = "setBg ()" & gt; Sverige & lt; / Input & gt; & Lt; Input type = "radio" name = "land" value = "danmark.png" onClick = "setBg ()" & gt; Denmark & ​​lt; / Input & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;   

Try this code This works updated with the latest

No comments:

Post a Comment