Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Rich Zimmerman
Rich Zimmerman
24,063 Points

Saving To Do List

I'm trying to create a tool for work with functionality similar to the To Do List project in the javascript section of the Front End Web Programming track.

My question is how/what language do you use to then save the information within the Task List. For example, I create a task list for say a Department that spans over multiple shifts. I want the list to be saved so that when the window is closed and reopened by another person, that information (The tasks i added) is still there for the next person/shift to see?

2 Answers

Hi Richard,

When I made my todo list project, I enhanced its functionality by creating persistence using HTML5's local storage techniques. I combined the ability to use local storage with the LZ-String compression algorithm so that I can squeeze as much space as possible out of any strings I save. None of the JavaScript has been minified, so you can take a look at how I did things. I do have comments over most sections.

How I saved the items was made two different local storage variables: one for completed tasks and one for incomplete tasks. Each one of those local storage items has an array stored into it as a string. It's easy to do this with the JSON.stringify command. And then you can use JSON.parse to parse the array from the string.

There are several different ways to go about this part, but you need to test for local storage functionality before trying to store data in local storage. All of the popular modern browsers have the ability to use local storage, but there are still a lot of older browsers in use today.

Rich Zimmerman
Rich Zimmerman
24,063 Points

well let me ask you this, as well. Specifically what is happening is i'm just creating and moving HTML elements. (This question is me getting a LITTLE bit ahead of myself in the project but i can at least get set on the right track).

Since i'm creating/moving HTML elements, when the site/tool would be hosted on a server, do the newly created/moved HTML elements stay where they are once you would close your browser/log off/come back on a different computer/browser at a different time?

I'm wondering if i'm just over-complicating it in my head since this is fairly new to me.

Thanks, and thank you for your previous response.

When you use local storage to store data, the data is local to that specific computer, which works for a to-do list program because there's no need to write simple text based tasks to a database. You will be able to access the data on that computer regardless of whether you refresh the page or close out of the browser, but it will be only on that specific computer. The data is only erased if you erase your local storage cache in your browser. And each individual list item will belong to the appropriate menu when you come back to the program, as you can see if you play around with my to-do list program.

Rich Zimmerman
Rich Zimmerman
24,063 Points

So basically for what i want to do, i'd need to do some back end programming like PHP or something? My goal for this project is to create a tool that is handed off to the following shift at my job.

I just wasn't sure if i'd need to learn PHP or some back end programming language before I can complete it or not.

Backend programming would be your best bet for sure, especially if you're dealing with any information that can be sensitive.

Rich Zimmerman
Rich Zimmerman
24,063 Points

Ok, cool. That'll send me in the right direction.

Thanks for your help.

No problem, Richard! Good luck on your project.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

This is something that I would like to see too unfortunately there's nothing in the library that follows it up!

Maybe we could see a follow up in a workshop that enhances it to make content saveable? :-)