LeoTheLibra
New Coder
Hi there I've been struggling with this piece of code for a while now and would appreciate any help!!
here is the part im stuck with:
[CODE lang="javascript" title="saveEntry"] // Create an event listener to save the entry when it changes
// (i.e. when the user types into the textarea)
function saveEntry(event) {
// TODO: Q1(c)(iii) Task 1 of 2
// Save the text entry:
// ...get the textarea element's current value
// (getting HTML input values is in Block 2 Part 2 Section 6)
text = textareaElement.value;
// ...make a text item using the value
// (demonstrated elsewhere in this file)
var data = text;
var item = makeItem("text", data);
// ...store the item in local storage using the given key
localStorage.setItem(key, item);
console.log("saved item", key, "=", textareaElement.value);
// (local storage is in Block 3 Part 5)
}
// TODO: Q1(c)(iii) Task 2 of 2
// Connect the saveEntry event listener to the textarea element 'change' event
// (demonstrated elsewhere in this file)
var textareaElement = document.querySelector("textarea");
textareaElement.addEventListener("onblur", saveEntry);
[/CODE]
here is the part im stuck with:
[CODE lang="javascript" title="saveEntry"] // Create an event listener to save the entry when it changes
// (i.e. when the user types into the textarea)
function saveEntry(event) {
// TODO: Q1(c)(iii) Task 1 of 2
// Save the text entry:
// ...get the textarea element's current value
// (getting HTML input values is in Block 2 Part 2 Section 6)
text = textareaElement.value;
// ...make a text item using the value
// (demonstrated elsewhere in this file)
var data = text;
var item = makeItem("text", data);
// ...store the item in local storage using the given key
localStorage.setItem(key, item);
console.log("saved item", key, "=", textareaElement.value);
// (local storage is in Block 3 Part 5)
}
// TODO: Q1(c)(iii) Task 2 of 2
// Connect the saveEntry event listener to the textarea element 'change' event
// (demonstrated elsewhere in this file)
var textareaElement = document.querySelector("textarea");
textareaElement.addEventListener("onblur", saveEntry);
[/CODE]
Last edited: