Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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


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 } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

To save the text entry when the textarea element changes and connect the saveEntry event listener to ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions