When creating a new text node, how can I have it be equal to the input written and submitted in the comment box? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

When creating a new text node, how can I have it be equal to the input written and submitted in the comment box?

https://code.sololearn.com/WPv3y6p3czzr/?ref=app When the person presses submits, what’s returned is undefined and not their comment. I thought comments.innerHTML might work but it doesn’t. I’ve also tried many other things but this has been the closest I’ve got to having something returned. I’m not sure how to access the value of the users comment and set it equal to the text node after being submitted. Any assistance would be appreciated.

14th Nov 2018, 6:29 AM
Thomas Czernek
Thomas Czernek - avatar
1 Answer
+ 2
Thomas The problem is that you are assigning the value of the textarea node to comments, outside of the function comment(). You need to assign just the textarea object to comments. And inside the function comment() you can get the current value on the textarea by using comments.value. You need to replace var comments = document.getElementById('commentBox').value; with var comments = document.getElementById('commentBox'); You also need to replace var node = document.createTextNode(comments.innerHTML); with: var node = document.createTextNode(comments.value); -OR- You can move... var comments = document.getElementById('commentBox').value; ...inside the function comment() It's up to you, either way will produce the results you want.
15th Nov 2018, 1:13 AM
ODLNT
ODLNT - avatar