Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to highlight the code in a textarea and "auto-copy" to the...

Status
Not open for further replies.

spewn

Programmer
May 7, 2001
1,034
i have some basic html that is in a textarea once a page loads...i want the user to highlight the code and copy (ctrl+c) to be able to paste the code somewhere else...

how do i accomplish this?

- g
 
Put the following sentence just above your textarea.
highlight the code and copy (ctrl+c) to be able to paste the code somewhere else

That should do it! [thumbsup2]

Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
A slight shortcut would be:
Code:
<div id="code" onclick="selectElement(this);" style="cursor:pointer;">
  <pre>
     your code here
  </pre>
</div>

The user would still need to press CTRL+C, but that'll select with just a click of the mouse anywhere inside the DIV
(it's javascript, btw)

-----

_brian.
 
oh, my bad, i just realized you wanted the Textarea. You can try my method or, possibly try:
Code:
<textarea id="mycode" onclick="selectElement(this);" style="cursor:pointer;"></textarea>

If you want your HTML to be read-only, then the DIV is going to be the easiest way than fooling with a textarea.

-----

_brian.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top