Jump to content

[SOLVED] Simple click to textarea problem


Nexy

Recommended Posts

Why Hello There! :) I seem to be having a problem with this little code:

 

<script type="text/javascript">
   function insertSmiley(smiley)
   {
var area = document.getElementById("pmmsg");
area.setValue(area.getValue() + smiley);
document.getElementById("pmmsg").focus();
   }
</script>

<?php
echo "<img src='board/images/smiles/happy.gif' alt='' onclick='insertSmiley(\"\")' />

<textarea id='pmmsg' name='pmmsg' rows='12' cols='45' tabindex='8'></textarea>";
?>

 

I have the last part in php because this is only part of the code. The problem is when I click the image, nothing happens. It doesn't add

": )" into the textarea. Any help would be appreciated.

 

Thank You! :)

Link to comment
Share on other sites

Sorry, I really had no idea what I was doing there. I just found those functions online and thought they were valid already. I looked more into this and I got this to work to some extent:

 

<script type="text/javascript">
     function insertText(text)
     {
       var elem = document.getElementById('pmmsg');
       elem.innerHTML += text;
       document.getElementById('pmmsg').focus();
     }
</script>

<?php
echo "<img src=\"board/images/smiles/happy.gif\" alt=\"\" onclick=\"insertText('  ')\" />

<textarea id='pmmsg' name='pmmsg' rows='12' cols='45' tabindex='8'></textarea>";
?>

 

The only problem now is if you click the textarea or an input button, the smiles stop working. If you never click the textarea or the input buttons, then those smiles work just fine. I'm using Firefox if that makes any difference. Any ideas?

 

Thank You Again! :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.