Trevors Posted April 8, 2006 Share Posted April 8, 2006 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 RegardsTrevors Quote Link to comment https://forums.phpfreaks.com/topic/6883-how-to-paste-text-into-a-textbox-using-singleclick/ Share on other sites More sharing options...
Vorotaev Posted April 8, 2006 Share Posted April 8, 2006 [!--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 RegardsTrevors[/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. Quote Link to comment https://forums.phpfreaks.com/topic/6883-how-to-paste-text-into-a-textbox-using-singleclick/#findComment-25068 Share on other sites More sharing options...
Trevors Posted April 9, 2006 Author Share Posted April 9, 2006 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 RegardsTrevorsI really appreciate the help. thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/6883-how-to-paste-text-into-a-textbox-using-singleclick/#findComment-25331 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.