0

I am working on an example and want I want to do now is to catch the value of some rows in a text area after pressing ENTER.
I have detected the ENTER key press using this JQuery function:

$('#output').keypress(function(event){

    var keycode = (event.keyCode ? event.keyCode : event.which);
    if(keycode == '13'){
        var read_lines = $('#output').val().split("\n");
        alert(read_lines);  
    }

});

and I try to catch the values in the #output text area using this:

var read_lines = $('#output').val().split("\n");
    alert(read_lines);

but it catch all the text in the text area not only the one I insert before pressing Enter key.

Can you please help me?

Here is my DEMO.

royhowie
  • 11,075
  • 14
  • 50
  • 67
orsina
  • 131
  • 11

1 Answers1

0

you have an array so you want the last one

alert(read_lines[read_lines.length-1]);

Bryan Dellinger
  • 4,724
  • 7
  • 33
  • 79
  • Thanks. I thought this before and finaly I solved this in that way because I removed all the rows after read statement – orsina May 08 '15 at 23:41