How to read line by line of a text area HTML tag How to read line by line of a text area HTML tag javascript javascript

How to read line by line of a text area HTML tag


Try this.

var lines = $('textarea').val().split('\n');for(var i = 0;i < lines.length;i++){    //code here using lines[i] which will give you each line}


This works without needing jQuery:

var textArea = document.getElementById("my-text-area");var arrayOfLines = textArea.value.split("\n"); // arrayOfLines is array where every element is string of one line


This would give you all valid numeric values in lines. You can change the loop to validate, strip out invalid characters, etc - whichever you want.

var lines = [];$('#my_textarea_selector').val().split("\n").each(function (){    if (parseInt($(this) != 'NaN')        lines[] = parseInt($(this));}