Javascript storing data

Posted by user985482 on Programmers See other posts from Programmers or by user985482
Published on 2012-06-02T15:13:03Z Indexed on 2012/06/02 16:48 UTC
Read the original article Hit count: 214

Filed under:

Hi I am a beginner web developer and am trying to build the interface of a simple e-commerce site as a personal project.The site has multiple pages with checkboxes.When someone checks an element it retrives the price of the element and stores it in a variable.But when I go to the next page and click on new checkboxes products the variable automaticly resets to its original state.How can I save the value of that variable in Javascript?

This is the code I've writen using sessionStorage but it still dosen't work when I move to next page the value is reseted.

How can I wright this code so that i dosen't reset on each page change.All pages on my website use the same script.

$(document).ready(function(){ var total = 0;

        $('input.check').click(function(){
            if($(this).attr('checked')){
                var check = parseInt($(this).parent().children('span').text().substr(1 , 3));
                total+=check;
                sessionStorage.var_name=0 + total;
                alert(sessionStorage.var_name);

            }else{
                var uncheck = parseInt($(this).parent().children('span').text().substr(1 , 3));
                total-=uncheck;


            }
        })

© Programmers or respective owner

Related posts about JavaScript