portfolio | contact
Tuesday the 15th

get a textarea's current line number and content.

Tuesday, 6:40 PM
just a quick and dirty piece of code to grab the line number and content from the current line of a text area. haven't tested it outside of firefox and chrome so your mileage may vary.
function getLine(edit){
var start = 0;
var lineNumber = 0;
var content = "";
if(typeof edit.selectionStart == 'undefined') {return false}

start = edit.selectionStart;

lineNumber = edit.value.substr(0,start).split("\n").length - 1;
content = edit.value.split("\n")[lineNumber];

return {"lineNumber": lineNumber, "content": content}

◄ back