Kod
<html>
<head>
<script type="text/javascript">
function insertAtCursor(myField, myValue) {
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}
}
// calling the function
//insertAtCursor(document.formName.fieldName, 'this value');
</script>
</head>
<body>
<form name="a">
<textarea id="b" cols="50" rows="5">Some text .. Some text .. Some text .. Some text .. Some text .. Some text .. Some text ..
Some text .. Some text .. Some text .. Some text .. Some text .. Some text .. Some text .. Some text .. Some text .. </textarea>
</form>
<input type="text" value=" !cos! " id="cos"><a href="javascript:void(0)" id="b" onclick="insertAtCursor(document.a.b, document.getElementById('cos').value);">Wstaw</a>
</body>
</html>
Dziala na IE i Mozilli, na Operze nie
google rox