Jump to content

How to paste text into a textbox using singleclick.


Trevors

Recommended Posts

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
Link to comment
Share on other sites

[!--quoteo(post=362819:date=Apr 8 2006, 12:35 PM:name=Trevors)--][div class=\'quotetop\']QUOTE(Trevors @ Apr 8 2006, 12:35 PM) [snapback]362819[/snapback][/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]

[code]// 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>[/code]
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.
Link to comment
Share on other sites

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.
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.