Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function add(el, ta, t1, t2){
var t = el.form.elements[ta], l;
t.value += '\n' + t1 + '\n';
l = t.setSelectionRange? t.value.length : t.value.replace(/\n/g, '').length;
t.value += '\n' + t2;
t.focus();
setCursorPosition(t, l, l);
}
function setCursorPosition(oInput, oStart, oEnd) {
if( oInput.setSelectionRange ) {
oInput.setSelectionRange(oStart,oEnd);
}
else if( oInput.createTextRange ) {
var range = oInput.createTextRange();
range.collapse(true);
range.moveEnd('character',oEnd);
range.moveStart('character',oStart);
range.select();
}
}
</script>
</head>
<body>
<form action="#" onsubmit="return false;">
<div>
<textarea name="bob" cols="50" rows="5">Some Stuff Here Already</textarea><br>
<input type="button" value="add" onclick="add(this, 'bob', 'Text_1', 'Text_2');">
</div>
</form>
</body>
</html>
Bookmarks