I have a search form that outputs merchant details (each merchant's name, phone, email address) into a table.
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.
The problem is that there may be more than one set of results, so the script cannot call a specific numbered function like I have done with textarea's below:
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");
}
HTML:
<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>
I was wondering if this would be possible? ...
<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 is there a more efficient way to approach this?