I'm trying to take the value from a textarea element and have it appended to a p element. The problem is that they are in different functions. Have tried using return and writing it outside the function but nothing is working. Please help.
javascript:
var div1 = document.getElementById("div1");
var div2 = document.getElementById("div2");
var newNote = document.getElementById("newNote");
var createNote = function(){
var noteTitleValue = prompt("Please label the new note:");
var noteContainer = document.createElement("li");
var textArea = document.createElement("textarea");
var noteTitle = document.createElement("label");
var submitButton = document.createElement("button"); submitButton.innerHTML = "Submit";
noteContainer.appendChild(noteTitle);
noteContainer.appendChild(textArea);
noteContainer.appendChild(submitButton);
div1.appendChild(noteContainer);
noteTitle.innerText = (noteTitleValue);
return textArea;
submitButton.onclick = submitClicked;
// submitButton.onclick = div1.removeChild(noteContainer);
var submitClicked = function (){
console.log(textArea.value); // not working.
console.log("test"); // not working either.
var savedNoteContainer = document.createElement("li");
var pArea = document.createElement("p");
savedNoteContainer.appendChild(pArea);
div2.appendChild(savedNoteContainer);
var textValue = (textArea.value);
pArea.innerHTML = textValue;
};
};
newNote.onclick = createNote;
css:
#div1 {
width: 200px;
height: 200px;
border: solid 1px #000;
}
#div2 {
width: 200px;
height: 200px;
border: solid 1px #000;
}
html:
<!DOCTYPE html>
<html>
<head>
<title>Todo App</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8">
</head>
<body>
<div id="div1"></div>
<div id="div2"></div>
<button id="newNote">Add Note</button>
<script type="text/javascript" src="app.js"></script>
</body>
</html>