Hmm, så kan det næsten kun være fordi dit areatext-element ikke har id'et "besked". Jeg paster lige mit kode ind fra
http://www.eksperten.dk/spm/763754 med "'(" indsat som smiley, så kan du jo prøve at se hvad forskellen er som gør det ikke virker (med sammenligning af dit kode).
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd"><html>
<head>
<script language="JavaScript" type="text/javascript">
function storePosition(textBox)
{
textBox.selection = GetSelection();
}
function insertText(textBoxId, strText)
{
var textBox = document.getElementById(textBoxId);
if(document.selection) //IE
{
var area = textBox.selection;
if(area != null)
area.text += strText;
else
textBox.value += strText;
}
else //FF
{
var oValue = textBox.value;
var end = textBox.selectionEnd;
textBox.value = oValue.substring( 0 , end ) + strText + oValue.substring( end , textBox.textLength );
textBox.setSelectionRange(end + strText.length, end + strText.length);
}
textBox.focus();
}
function GetSelection()
{
if(document.selection)
return document.selection.createRange();
else if(window.getSelection)
return window.getSelection();
return null;
}
</script>
</head>
<body >
<table cellspacing="0" cellpadding="3">
<tr>
<td>
<textarea id="txtArea" name="txtLayoutViewer"
onmouseup="storePosition(this)"
onmousedown="storePosition(this)"
onkeyup="storePosition(this)"
onkeydown="storePosition(this)"
onfocus="storePosition(this)"
rows="10"
cols="20">iiiiiii iiijjjj jjjjjjkkkk kkkkkk
</textarea>
</td>
</tr>
<tr>
<td>
<input type="button" value="insert text at cursor position" onclick="insertText('txtArea', '\'(');" />
</td>
</tr>
</table>
</body>
</html>
Mvh.
- Snap