michelle
10-29-2003, 06:14 AM
I have a text field in which I want to add some predefined text by clicking some links.
The problem I am having is to figure out how to add the text where the text marker is situated. The function I have now just adds it to the end.
I then started looking at execCommand, but there doesn't seem to any command for inserting plain text.
Is there such a thing?
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/commandids.asp
<My Page>
<script>
function insertText(myText) {
var origContent = document.myForm.editor.value;
var newContent = origContent + myText;
document.myForm.editor.value = newContent;
}
</script>
<form action="" name="myForm" id="myForm">
<textarea cols="30" rows="5" name="editor" id="editor"></textarea>
</form>
<a href="#" onClick="insertText('this is a predefined text');">Predefined text 1</a><br>
<a href="#" onClick="insertText('this is another predefined text');">Predefined text 2</a>
</My Page>
Any thoughts?
// Michelle
The problem I am having is to figure out how to add the text where the text marker is situated. The function I have now just adds it to the end.
I then started looking at execCommand, but there doesn't seem to any command for inserting plain text.
Is there such a thing?
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/commandids.asp
<My Page>
<script>
function insertText(myText) {
var origContent = document.myForm.editor.value;
var newContent = origContent + myText;
document.myForm.editor.value = newContent;
}
</script>
<form action="" name="myForm" id="myForm">
<textarea cols="30" rows="5" name="editor" id="editor"></textarea>
</form>
<a href="#" onClick="insertText('this is a predefined text');">Predefined text 1</a><br>
<a href="#" onClick="insertText('this is another predefined text');">Predefined text 2</a>
</My Page>
Any thoughts?
// Michelle