javascript add text into a form
Posted: Tue Dec 10, 2002 6:03 pm
Like the emoticons on this form, how can i use javascript to add something like Clicky smiles?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
...
function emoticon(text) {
text = ' ' + text + ' ';
if (document.post.message.createTextRange && document.post.message.caretPos) {
var caretPos = document.post.message.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
document.post.message.focus();
} else {
document.post.message.value += text;
document.post.message.focus();
}
}
...
<textarea name="message" rows="15" cols="35" wrap="virtual" tyle="width:450px" tabindex="3" class="post" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);"></textarea>Code: Select all
function emoticon(text) {
text = ' ' + text + ' ';
if (opener.document.formsї'post'].message.createTextRange && opener.document.formsї'post'].message.caretPos) {
var caretPos = opener.document.formsї'post'].message.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
opener.document.formsї'post'].message.focus();
} else {
opener.document.formsї'post'].message.value += text;
opener.document.formsї'post'].message.focus();
}Code: Select all
<script language="Javascript" type="text/javascript">
<!--
function insert(text) {
text = ' ' + text + ' ';
if (document.post.message.createTextRange && document.post.message.caretPos) {
var caretPos = document.post.message.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
document.post.message.focus();
} else {
document.post.message.value += text;
document.post.message.focus();
}
}
//-->
</script>
<a href="javascript:insert(':)')">SMILE</a><p>
<form name="post" action="next.html" method="POST">
<textarea name="message" rows="15" cols="35" wrap="virtual" style="width:450px" tabindex="3" class="post"></textarea>
</form>