Depending on how well you want this done.
A quick and dirty way to get started would be to add a counter every time return is hit.
To get started:
document.getElementById("myTextArea").on("keypress", function(event) {
var key = event.key;
if(key == 13) {
addLineCount();
}
});
This won't work if you start to delete lines though. You can potentially catch each event and check if it's deleting a return statement and decrease the count when it does.
Another thing you can do is count all the return characters in the textarea:
//the dollar sign is just what I use to know it's a DOM element
var $textToCount = document.getElementById("myTextArea");
$textToCount.on("keypress", function(event) {
//get the number of newlines
var lines = $textToCount.innerHtml.match("\n").length;
setLineCount(lines);
});
This will work but is less efficient. Also, it will have some errors if you use text-wrap where a line number will not represent a wrapped line as just one.
If you don't know how to add the line count column, try this:
function setLineCount(count) {
var out = "";
for(var c < count) {
out += count+"<br>";
}
document.getElementById("lineCountColumn").innerHTML = out;
}
And if you want to do an all functional line counter where text wrapping still numbers the lines correctly, you're going to have to do something clever. In most cases, some combination of the code shown here and in the link will give you a mostly functional line counter. It's up to you to put the pieces together.