Jump to content

Archived

This topic is now archived and is closed to further replies.

Trevors

How to paste text into a textbox using singleclick.

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

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.