Convert Lines
by Salem Yaslim
HTML
<textarea rows="25" cols="50" id="lines">Line1
Line2
Line3
Line4</textarea><br/>
<button onclick="convert()">Convert Lines</button><br/>
JavaScript
var convert_lines = function(id){
var self = this,
_Element;
var constructor = function(){
try{
_Element = document.getElementById(id);
}catch(e){
try{
_Element = { value:id };
}catch(e){
alert(e);
return;
}
}
}();
return{
convert:function(){
var lines = (_Element.value).split("\n"),
_text = "";
for(var i = lines.length-1;i >= 0;i-- ){
_text += lines[i]+"\n";
}
_Element.value = _text.replace(/\n$/, "");
return _text;
}
};
};
window.convert = function(){
(new convert_lines("lines")).convert();
}