Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9153019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:11:26+00:00 2026-06-17T12:11:26+00:00

Each user can dynamically create a table from a form. I am trying to

  • 0

Each user can dynamically create a table from a form. I am trying to save the table and its current state to local storage every time a change is made or the person exits the page. Name stores the name of the user and I am using it as a key. However, it is not working for me. I think I am saving the data when I need to using the saveData function and parsing it when I need to with the showData function. Can anyone tell me where I am going wrong please?

    userDiv.onclick=(function() {
            alert($(this).attr("id"));
            name= $(this).attr("id");
            window.location.href = "Createtask.html";
            showData();//TRYING TO SHOW THE USER'S TABLE WHEN PAGE OPENS
            }


    function makeChart() {
     table = document.createElement('table');
    var taskName = document.getElementById('taskname').value,
        header = document.createElement('th'),
        numDays = document.getElementById('days').value, //columns
        howOften = document.getElementById('times').value, //rows
        row,
        r,
        col,
        c;
    var counter = 0;
    var target = numDays * howOften;

    var cel = null;
    var myImages = new Array();
    myImages[0] = "http://www.olsug.org/wiki/images/9/95/Tux-small.png";
    myImages[1] = "http://a2.twimg.com/profile_images/1139237954/just-logo_normal.png";
    var my_div = document.createElement("div");
    my_div.id = "showPics";
    document.body.appendChild(my_div);
    var newList = document.createElement("ul");
    my_div.appendChild(newList);

    if (taskName == '' || numDays == '') {
        alert('Please enter task name and number of days');
    }
    if (howOften == '') {
        howOften = 1;
    }
    if (taskName != '' && numDays != '') {

        for (var i = 0; i < myImages.length; i++) {
            var allImages = new Image();
            allImages.src = myImages[i];
            allImages.onclick = function (e) {
                if (sel !== null) {
                    sel.src = e.target.src;
                    my_div.style.display = 'none';
                    sel.onclick = null;
                    counter++;
                    sel = null;
                    if (counter == target) {
                      alert("Show some fireworks "+name+" gets a reward");
                    }
                }
            };

            var li = document.createElement('ul');
            li.appendChild(allImages);
            newList.appendChild(li);
        }
        my_div.style.display = 'none';

        header.innerHTML = taskName;
        table.appendChild(header);

        function addImage(col) {
            var img = new Image();
            img.src = "http://cdn.sstatic.net/stackoverflow/img/tag-adobe.png";
            col.appendChild(img);
            img.onclick = function () {
                my_div.style.display = 'block';
                sel = img;
                saveData();
            };
        }
        for (r = 0; r < howOften; r++) {
            row = table.insertRow(-1);
            for (c = 0; c < numDays; c++) {
                col = row.insertCell(-1);
                addImage(col);
            }
        }
        document.getElementById('theRealHoldTable').appendChild(table);
        document.getElementById('createChart').onclick = null;
        saveData();/CALLING THE LOCAL STORAGE WHEN TABLE IS CREATED
    }
}

function saveData(){
     localStorage.setItem(name, JSON.stringify(table.innerHTML));
}

function showData(){
    JSON.parse(localStorage.getItem( name ));
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:11:27+00:00Added an answer on June 17, 2026 at 12:11 pm

    you are trying to stringify html-markup, which is not working! you are only able to JSON.stringify an js-object which means an instance of a class, an object literal or an array:

    // this works because it is an instance
    var objInstance = new SomeClass();
    JSON.stringfy(objInstance);
    
    // this works as it is an object-literal
    var objLiteral = { mykey: 'myvalue' };
    JSON.stringfy(objLiteral);
    
    // this works as it is an array
    var arr = [1, 2, 3]
    JSON.stringfy(arr);
    
    
    // THIS DOES NOT WORK!!!
    JSON.stringify('<div>...</div>');
    

    just strip the JSON.stringify part of your methods, that should work because element.innerHTML already returns a string:

    function saveData(){
      localStorage.setItem(name, table.innerHTML);
    }
    
    function showData(){
      localStorage.getItem(name); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a view where the user can click a plus button,
I have a page on which user can dynamically create some identical groups of
I am trying to display a table dynamically loaded from database with dynamically created
As you can see here , I'm allowing a user to dynamically create a
I writing an app in python for google app engine where each user can
My Rails application makes use of Time.zone so that each user can set their
I have 2 entities: User and Avatar . Each user can choice one avatar
My application supports internationalization and localization, each user can choose his preference language and
I have an application where for each object the user can specify his own
I have make a messaging system in which user can send messages to each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.