I'm struggling with this code. I need to Save a text entry doing the following: // ...get
Fantastic news! We've Found the answer you've been seeking!
Question:
I'm struggling with this code.
I need to Save a text entry doing the following:
// ...get the textarea element's current value // ...make a text item using the value // ...store the item in local storage using the given key
and then to Connect the saveEntry event listener to the textarea element 'change' event.
The existing variables and functions have already been given to me. Code lines I need to add are at the bottom of the code. Please see below
function addTextEntry(itemKey, initialText, isNewEntry) { // Make textarea element to edit the entry var textElement = document.createElement("textarea"); textElement.rows = 5; textElement.placeholder = "(new entry)"; // Set the textarea's value to the given text (if any) textElement.value = initialText; // Add a section to the page containing the textarea addSection(itemKey, textElement); // If this is a new entry (added by the user clicking a button) // move the focus to the textarea to encourage typing if (isNewEntry) { textElement.focus(); } // Make event listener to save the entry when it changes // (i.e. when the user types into the textarea) function saveEntry() { // A new version of this function is created every time addTextEntry is called, // so it can access all the variables available in this call to addTextEntry console.log("saveEntry called with variables in scope:", { itemKey, initialText, isNewEntry, textElement, }); // Save the text entry: // ...get the textarea element's current value // ...make a text item using the value // ...store the item in local storage using the given key } // Connect the saveEntry event listener to the textarea element 'change' event }
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date: