Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Problem with inserting text in a textarea.

    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.

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

    Code:
    //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.

  • #2
    New Coder
    Join Date
    Aug 2008
    Posts
    60
    Thanks
    6
    Thanked 6 Times in 6 Posts
    Use this...
    Code:
    //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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •