...

View Full Version : Problem with inserting text in a textarea.



Dewd
10-07-2008, 10:46 PM
Hello,

I am making a small message board on my own, but I have ran into a problem with emotion buttons.

Anytime I click on one it will put the code in as expected but after that it refreshs thus making it disappear.

This is my first venture into Javascript. :p

The code used for this function (Note that this is in a php script):



//This is in the header.
<script>
function addSmiley(emotion)
{
document.msgform.msg.focus();
document.msgform.msg.value+=emotion;
}
</script>

//This is further down the script, after getting/submitting messages.
<form name="msgform">
Enter your name: <input type="text" name="name" size="30"><br/>
<br/>Enter your message:<br/>
<table cellpadding="0">
<tr>
<td>
<textarea name="msg" cols="40" rows="5"></textarea>
</td>
</tr>
<tr>
<td>
<div align="center">
<input name="emot_happy" type="image" src="images/emotions/emot_happy.png" onClick="addSmiley(':)');" title="Emot Happy.">
<input name="emot_unhappy" type="image" src="images/emotions/emot_unhappy.png" onClick="addSmiley(':(');" title="Emot Unhappy.">
<input name="emot_grin" type="image" src="images/emotions/emot_grin.png" onClick="addSmiley(':D');" title="Emot Grin.">
<input name="emot_wink" type="image" src="images/emotions/emot_wink.png" onClick="addSmiley(';)');" title="Emot Wink.">
<input name="emot_lol" type="image" src="images/emotions/emot_lol.png" onClick="addSmiley(':lol:');" title="Emot Lol.">
<input name="emot_blush" type="image" src="images/emotions/emot_blush.png" onClick="addSmiley(':blush:');" title="Emot Blush.">
<input name="emot_dumb" type="image" src="images/emotions/emot_dumb.png" onClick="addSmiley(':dumb:');" title="Emot Dumb.">
<input name="emot_funny" type="image" src="images/emotions/emot_funny.png" onClick="addSmiley('XD');" title="Emot Funny.">
<input name="emot_nerdygrin" type="image" src="images/emotions/emot_nerdygrin.png" onClick="addSmiley('8D');" title="Emot Nerdygrin.">
<input name="emot_shocked" type="image" src="images/emotions/emot_shocked.png" onClick="addSmiley('D:');" title="Emot Shocked.">
<input name="emot_unamused" type="image" src="images/emotions/emot_unamused.png" onClick="addSmiley(':|');" title="Emot Unamused.">
<input name="emot_reallybiggrin" type="image" src="images/emotions/emot_reallybiggrin.png" onClick="addSmiley('^^');" title="Emot Reallybiggrin.">
</div>
</td>
</tr>
</table>
<br/><input type="submit" value="Submit">

Thanks for any help.

uncrocks
10-08-2008, 02:42 AM
Use this...


//This is in the header.
<script>
function addSmiley(emotion)
{
document.msgform.msg.focus();
document.msgform.msg.value+=emotion;
}
</script>
<style>
.emot{cursor:pointer;}
</style>

//This is further down the script, after getting/submitting messages.
<form name="msgform">
Enter your name: <input type="text" name="name" size="30"><br/>
<br/>Enter your message:<br/>
<table cellpadding="0">
<tr>
<td>
<textarea name="msg" cols="40" rows="5"></textarea>
</td>
</tr>
<tr>
<td>
<div align="center">
<img class="emot" name="emot_happy" src="images/emotions/emot_happy.png" onClick="addSmiley(':)');" title="Emot

Happy.">
<img class="emot" name="emot_unhappy" src="images/emotions/emot_unhappy.png" onClick="addSmiley(':(');"

title="Emot Unhappy.">
<img class="emot" name="emot_grin" src="images/emotions/emot_grin.png" onClick="addSmiley(':D');" title="Emot

Grin.">
<img class="emot" name="emot_wink" src="images/emotions/emot_wink.png" onClick="addSmiley(';)');" title="Emot

Wink.">
<img class="emot" name="emot_lol" src="images/emotions/emot_lol.png" onClick="addSmiley(':lol:');" title="Emot

Lol.">
<img class="emot" name="emot_blush" src="images/emotions/emot_blush.png" onClick="addSmiley(':blush:');"

title="Emot Blush.">
<img class="emot" name="emot_dumb" src="images/emotions/emot_dumb.png" onClick="addSmiley(':dumb:');"

title="Emot Dumb.">
<img class="emot" name="emot_funny" src="images/emotions/emot_funny.png" onClick="addSmiley('XD');" title="Emot

Funny.">
<img class="emot" name="emot_nerdygrin" src="images/emotions/emot_nerdygrin.png" onClick="addSmiley('8D');"

title="Emot Nerdygrin.">
<img class="emot" name="emot_shocked" src="images/emotions/emot_shocked.png" onClick="addSmiley('D:');"

title="Emot Shocked.">
<img class="emot" name="emot_unamused" src="images/emotions/emot_unamused.png" onClick="addSmiley(':|');"

title="Emot Unamused.">
<img class="emot" name="emot_reallybiggrin" src="images/emotions/emot_reallybiggrin.png" onClick="addSmiley

('^^');" title="Emot Reallybiggrin.">
</div>
</td>
</tr>
</table>
<br/><input type="submit" value="Submit">

Using the input image causes the page to refresh, the img tag doesn't.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum