Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-03-2012, 03:35 PM   PM User | #1
Subyne Simean
New Coder

 
Join Date: Nov 2006
Posts: 21
Thanks: 3
Thanked 1 Time in 1 Post
Subyne Simean is an unknown quantity at this point
Copy text output from database without assigning unique ID to each field

I have a search form that outputs merchant details (each merchant's name, phone, email address). I'm looking to have a copy button next to each one of these fields so users can click on it and copy it to their clipboard (the text gets highlighted when copied).

My users will be browsing with IE9 only (it's an unpaid work project and as far as I'm aware, the copy-to-clipboard JavaScript only works in IE).

I use similar JavaScript for copying from text areas...

Code:
function highlightmetasearch01() {
document.copydata01.text2copy01.select(); document.copydata01.text2copy01.focus(); }
function copymetasearch01() {
highlightmetasearch01();
textRange = document.copydata01.text2copy01.createTextRange();
textRange.execCommand("RemoveFormat");
textRange.execCommand("Copy"); }

function highlightmetasearch02() {
document.copydata02.text2copy02.select(); document.copydata02.text2copy02.focus(); }
function copymetasearch02() {
highlightmetasearch02();
textRange = document.copydata02.text2copy02.createTextRange();
textRange.execCommand("RemoveFormat");
textRange.execCommand("Copy"); }

...

<textarea name="text2copy01">The first textarea.</textarea>
<br />
<button onclick="copymetasearch01();return false;">COPY</button>


<textarea name="text2copy02">The second textarea.</textarea>
<br />
<button onclick="copymetasearch02();return false;">COPY</button>
...but the drawback with this is that I'm required to make each copy-to-clipboard function unique to each text area.

I can only output one set block of code for a merchant with PHP, so this prevents me from replicating a function script and incrementing the function/textarea/button numbers.

I was wondering if this would be possible?

Code:
<td><span>Name from DB here</span> <button onclick="copy and highlight text within most recent span tag">COPY</button></td>

<td><span>Phone from DB here</span> <button onclick="copy and highlight text within most recent span tag">COPY</button></td>

<td>Other text here that shouldn't be highlighted or copied <span>Email address from DB here</span> <button onclick="copy and highlight text within most recent span tag">COPY</button></td>
..or if you have a more efficient way to approach this? I'm very grateful for any help that can be provided or any hints and tips that'd point me in the right direction.
Subyne Simean is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:51 AM.


Advertisement
Log in to turn off these ads.