Question

I am making a webapp, that uses mobiscroll as a number counter. The numbers are saved via a submit button below it. The problem I have is whenever the user presses the home button, when the webapp is reloaded, it resets the number list. I figured it would be a good idea to save the value to localstorage,and recall it when the app is reopened. Now that's where I am stuck.

Here is the function for the button press that works fine:

<script type="text/javascript">
    function save_it() {
        //Save the scroll value for later
        var scrollsave = $('#i').scroller('getValue');
        localStorage.setItem("scrollsave", scrollsave);
        localStorage.saveServer
    }
</script>

I have a function further up, that is giving me trouble, and refusing to work proper, I have tried the following methods:

My first attempt to assign

<script type="text/javascript">
    $(function () {
        var scrollstate = localStorage["scrollsave"];
        if (scrollstate != null) {
            $('#i').scroller('setValue', scrollstate);
        }

    });
</script>

I get an error of, Object x,x,x,x has no method 'join'.

Second attempts to convert to array and back, but no luck.

var oldscroll = localStorage.getItem["scrollsave"];
var finalsaved = SON.parse(oldscroll);
if (finalsaved != null) {
    $('#i').scroller('setValue', finalsaved);

The documentaion on mobiscroll is here http://docs.mobiscroll.com/22/mobiscroll-core . And it says, "scroller values from the data parameter passed as array".

My key, scrollsave is stored with a value of 1,2,1,1 . Which seems to meet the correct formatting to throw into the mobiscroll part.

I have a feeling there is something trivial I am overlooking, but I can't figure out what.

Was it helpful?

Solution

var oldscroll = localStorage.getItem["scrollsave"]; should be var oldscroll = localStorage.getItem("scrollsave");

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top