Bummer! You must be logged in to access this page.

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

JavaScript Todo Application

I created a ToDo application similar to what was made in a previous course here on TreeHouse. A lot of the code is similar except I need the text inputs to save when the users hits the enter key. The initial add/submit button works fine but the edit does not toggle when the user is focused and hits enter. To be more clear what I want: the users hits edit, modifies the field, then can hit enter to leave the field and save the edit.

Below is a link to all the code. The code specific to the keyboard events is at the very bottom of the javascript section.

http://jsbin.com/madutesebi/1/edit?html,css,js,output

Thanks in advance to anyone that can help!!

1 Answer

Steven Parker
Steven Parker
243,318 Points

You don't have a keyup event listener for the input field(s).

I see some code that starts with ...

document.getElementsByTagName("input")[2].addEventListener("keyup", ...

Perhaps this is intended to to create a keyup listener for the input field, but these have not been created yet at page load time. This should be done individually (with slight modification) in the TaskEvents function, or collectively with a delegated handler.

Steven,

Thank you so much!! You got it exactly. I had put the event handler outside the functions and they only ran one time when the page loaded, before the list items were created. I move the event handler inside the " add task" function and attached it to each new item when it was created.

Thanks again for the advice and prompt response! You really helped me out. I had spent several hours tinkering with it before asking and you saved me many more.