0

Got stacked, I have a simple strikethrough task list html script that works fine, however, I would like to have the browser to store the data and save it persistently so that if I refresh the page or I come back to the task list on a later time I will still have the tasks already done striked.

Here is my html code:


<!doctype html public "-//w3c//dtd html 3.2//en">
 <html>
   <head>
     <title>Demo of Strikethrough JavaScript string object</title>
     <script type="text/javascript">
       function my_fun(j){
         var chkbox ="ckb" + j;
         var my_span ="my_span" + j;
         var msg = chkbox + " " + my_span;
         if(document.getElementById(chkbox).checked){ 
           document.getElementById(my_span).style.textDecoration='line-through';
         }else{
           document.getElementById(my_span).style.textDecoration='none';
         }
      }
    </script>
  </head>
  <body>

    <form name=form1 method=post action=check.php>
      <input type=checkbox id=ckb1 value=1 onclick=my_fun(1);><span id='my_span1'>This is job         number 1</span> <br>
      <input type=checkbox id=ckb2 value=2 onclick=my_fun(2);><span id='my_span2'>This is job number 2</span> <br>
      <input type=checkbox id=ckb3 value=3 onclick=my_fun(3);><span id='my_span3'>This is job number 3</span> <br>
    </form>
  </body>
</html>

Thank you all

wharding28
  • 1,271
  • 11
  • 13
Daniele Pais
  • 141
  • 1
  • 1
  • 10

1 Answers1

0

If you want a browser independent approach, you likely want to store this in a cookie, and then read the data back in on load.

You likely want to use a utility library to help you manage the cookie data. Here is a discussion of using jQuery for this.

jquery save json data object in cookie

Community
  • 1
  • 1
DrLivingston
  • 788
  • 6
  • 15