Link to home
Start Free TrialLog in
Avatar of Putoch
PutochFlag for Afghanistan

asked on

cookies & HTML

I am working on a html table and I want to set cookies from the table - that bit I think it okay but what I need to do then is to read that cookie ( from one big long cookie string) and break it down and repost it back to the table when I click my get cookie button.

 I am lost in how to get that bit to work -
EE-First-Sample-Code.txt
Avatar of Putoch
Putoch
Flag of Afghanistan image

ASKER

I got a little further since but not there yet either …This is my code so far - my set cookie part is working - what is not working is trying to clear the table and then repopulate from the cookie - i.e. the get cookie part ….
Experts-Exchange-Code.txt
Avatar of Julian Hansen
why not just use local storage

localStorage.setItem and localStorage.getItem
  <button id="save" class="btn btn-primary">Save</button>
  <button id="restore" class="btn btn-primary" style="display: none">Restore</button>
  <table class="table" id="theTable">
    <tr>
      <td>One</td>
      <td>Two</td>
      <td>Three</td>
    </tr>
    <tr>
      <td>One</td>
      <td>Two</td>
      <td>Three</td>
    </tr>
    <tr>
      <td>One</td>
      <td>Two</td>
      <td>Three</td>
    </tr>
    <tr>
      <td>One</td>
      <td>Two</td>
      <td>Three</td>
    </tr>
    <tr>
      <td>One</td>
      <td>Two</td>
      <td>Three</td>
    </tr>
  </table>

Open in new window

jQuery
<script>
$(function() {
  $('#save').click(function() {
    localStorage.setItem("theTable", $('#theTable').html());
    $('#theTable').html('')
    $('button').toggle();
  });
  $('#restore').click(function() {
    var html = localStorage.getItem("theTable");
    $('#theTable').html(html)
    $('button').toggle();
  });
});
</script>

Open in new window

Working sample here
Avatar of Putoch

ASKER

Thank you,
The table is dynamic so can’t set the exact table - rows and columns can be added.Also we cannot use jQuery - life would be so much easier if we could
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Putoch

ASKER

Thank you,
 but that answers it to a specific table - I know what you are saying but I need nested loops to fill my 2d array type table , this doesn’t work - Honestly I have given up on it now - Thanks a mill for posting anyway
but I need nested loops to fill my 2d array type table
Can you explain this a bit more - what are you trying to achieve with this?