Click to See Complete Forum and Search --> : Button to insert text in field


hammerslane
01-13-2004, 04:14 AM
you know in a reply, when you click the little yellow smilies, it inserts :) or :confused: etc... well i'm basically trying to figure out how to do that.

i hope i'm allowed to use the code from these forums... if not, just let me know.

so far i have this code:<html>
<head>
<script language=javascript>
function smilie(thesmilie) {
// inserts smilie text
document.fieldname.message.value += thesmilie+" ";
document.fieldname.message.focus();
}
</script>
</head>

<body>
<form action="nextpage.php">

<textarea type="textarea" name="description" class="fieldname" rows=6></textarea>

<a href="javascript:smilie(':text to be inserted:')">
<img src="lovelybutton.gif" alt="Insert Text" border="0"></a>

<input type=submit>
</form>

</body>
</html>

the above code doesn't work... can someone tell me if there's an error i've made? (well.. copied... ;))

thanks!

Fang
01-13-2004, 05:04 AM
The form and textarea have different names to "fieldname" and "message"

hammerslane
01-13-2004, 05:14 AM
thanks!

:)

hammerslane
01-13-2004, 06:07 AM
i've got another question about what i'm doing at the moment... in the <textarea> if someones types
"any old sample text" and then presses the button to insert :inserted text:, text in the <textarea> looks like this:any old sample text:inserted text:Is there any way to make the :inserted text: inserted on a line below, and put a carriage return after it inserts the text? I tried %0D and that didn't work, <br> just pastes in the characters "<br>" and not a break.
thanks once again

Kor
01-13-2004, 06:52 AM
to insert a break line in textarea (or in javascript alert) use

\n

or
+'\n'+ if you set the string value using javascript