Solved

Javascript and HTML5 to do list

Posted on 2014-02-13
7
338 Views
Last Modified: 2014-03-01
I'm trying to get a HTML5 to do list to work. When I add items to the list I should be able to copy past the url to another tab and it should display all the contents on the list but it is not. How do I fix it? This is from a tutorial that I'm following to learn HTML5 and Javascript. Attached is the HTML file. Thank you.
todo-basic.html
0
Comment
Question by:centem
7 Comments
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 39856891
Do you have jquery in the '_scripts' directory like it shows here?

<script src="_scripts/jquery-1.8.2.min.js"></script>

Open in new window

0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39856922
Hey Dave, can you check out this js quandary http:Q_28364025.html
0
 

Author Comment

by:centem
ID: 39856929
Yes I do.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:centem
ID: 39856940
What am I missing?
0
 
LVL 22

Expert Comment

by:Snarf0001
ID: 39857058
You're never actually calling the "loadToDO" function.


$(document).ready(function (e) {
        var theList = document.getElementById('theList');
        $('#saveAll').click(function (e) {
            e.preventDefault();
            localStorage.setItem('todoList', theList.innerHTML);
        });
        $('clearAll').click(function (e) {
            e.preventDefault();
            localStorage.clear();
            location.reload();
        });
        function loadToDo() {
            theList.innerHTML = localStorage.getItem('todoList');
        }

        loadToDo();   //this is missing from your code
    });
0
 
LVL 42

Expert Comment

by:Chris Stanyon
ID: 39857610
Snarf's right, but you have some other problems as well. The first time you load your page, or subsequently load after a clear(), your UL will be empty, so you'll never see the Enjoy Life text, and actually have nowhere to type into. You can solve this by adding a simple if statement. If there is no localStorage, drop in a static value.

You also have the ID selector missing from your clearAll() function.

Finally, not really a problem - more of an observation. You're mixing javascript and jquery - not sure why. You also have the javascript:void() calls on your links but they're not needed because you're using e.preventDefault()

Anyway, have a look at this:

$(document).ready(function() {
	var theList = $('#theList');
	loadToDo();

	$('#saveAll').click(function(e){
		e.preventDefault();
		localStorage.setItem('todoList', theList.html());
	});
		
	$('#clearAll').click(function(e){
		e.preventDefault();
		localStorage.clear();
		location.reload();
	});

	function loadToDo(){
		if (toDoList = localStorage.getItem('todoList')) {
			theList.html(toDoList);
		} else {
			theList.html('<li>Enjoy Life :)</li>');
		};
	}
});

Open in new window

0
 
LVL 42

Expert Comment

by:Chris Stanyon
ID: 39897436
How is that the answer if you already had the jQuery library in the right place????
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now