Jump to content


Photo

How to paste text into a textbox using singleclick.


  • Please log in to reply
2 replies to this topic

#1 Trevors

Trevors
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 08 April 2006 - 04:05 PM

Heya all i got a small question on how to paste a text when you single click it and paste it into a textbox using javascript.
Im trying to create a "message function" on one of my websites but i have never been any good at javascripting.
I got one box where i list a persons friends and one send message form, when someone clicks on one of the names on the friendlist it should paste into the send to box.
Is there any easyway doing this?


Best Regards
Trevors

#2 Vorotaev

Vorotaev
  • Members
  • PipPip
  • Member
  • 27 posts
  • LocationCanada

Posted 08 April 2006 - 07:39 PM

[!--quoteo(post=362819:date=Apr 8 2006, 12:35 PM:name=Trevors)--][div class=\'quotetop\']QUOTE(Trevors @ Apr 8 2006, 12:35 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Heya all i got a small question on how to paste a text when you single click it and paste it into a textbox using javascript.
Im trying to create a "message function" on one of my websites but i have never been any good at javascripting.
I got one box where i list a persons friends and one send message form, when someone clicks on one of the names on the friendlist it should paste into the send to box.
Is there any easyway doing this?
Best Regards
Trevors
[/quote]

// Function to paste friends.
<script type="text/javascript">
function pastefr(friend) {
    document.getElementById('recipient').value = document.getElementById(friend).innerText;
}

</script>

// Example of friends list.
<select size="4" onchange="javascript: pastefr(this.options[selectedIndex].id)">
    <option id="f1">Michael87</option>
    <option id="f2">xx_Hot_Debbi_xx</option>
    <option id="f3">z3r0_t0n</option>
    <option id="f4">Amy_Winston</option>
</select>

// Example of form.
<form action="sendmessage.php" method="POST">
    <input type="text" size="16" id="recipient" /><br />
    <textarea cols="40" rows="5" id="message"></textarea><br />
    <button type="submit">Send message</button>
</form>
All the better if you have the screenname listed as a value in the <option> tag. Of course, this can be modified to use something other than a SELECT tag, but you get the gist.

#3 Trevors

Trevors
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 09 April 2006 - 08:50 PM

Ah great work Vorotaev i really appreciate it.

Is it somehow possible to block so you cant add more than 1 of the same name? or maybe block so you can only add 10 names overall ?

Best Regards
Trevors

I really appreciate the help. thanks a lot.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users