Reputation: 301
After you run the html for the first time, comment the lines that store the local storage values. Then enter some value in the comment box and press enter. The comments can be entered for the first item in the list. If you try to do the same for the next item, they don't work. :( Comments can't be entered anywhere apart from the first box.
JSBin - http://jsbin.com/dosicuteku/2/
Upvotes: 0
Views: 39
Reputation: 388416
The problem is how you are reading the value of the input
box, you are using document.querySelector('.commentsBox').value
to read the value of the input
element on which the keyup
has happened, but here the problem is document.querySelector('.commentsBox')
will always return the value of the first element with the class commentsBox
, so if there are more than 1 element then it will always return the first element not the element where the keypress has happened.
In your case this
inside the keyup
event refer to the element which raised the event so you can simply use this.value
to get the value of the current element. So change the following lines
//var comVal = document.querySelector('.commentsBox').value;
var comVal = this.value;
//....
//text = document.querySelector('.commentsBox').value;
text = this.value;
Demo: Fiddle
Upvotes: 1