View Full Version : select all for text in text box

02-28-2007, 03:41 AM
I am looking for a script for select all to highlights text in text box, Just like the one in every code page in DD code pages, it is much better if it is auto saved to clipboard, ( acting like Cntrl +A, Cntrl +C )

02-28-2007, 03:44 AM
Something like this:


(Note: the "Copy to Clipboard" function only works in IE [as far as I am aware of].)

Hope this helps.

02-28-2007, 04:06 AM
The method, actually methods - focus() and select(), for selecting text in a form element like a textarea or text input is rather simple. In most basic terms it is:


where element represents the form element. Form elements can be 'gotten' in a variety of ways and the best way usually depends upon the markup and other things like - the rest of the script.

Having the text data that you select transferred to the clipboard is a bit more complicated. There is an IE only method and I think there is a way that works in some other browsers or at least a way to make a sort of virtual clipboard.

Accessing the user's clipboard is impolite as, it potentially and in most cases will wipe out any text or image data already on the user's clipboard.

How this is done in IE was gone into in detail here:


For other browsers, there is a link to info on that in that thread:


I'm not sure (as already mentioned) if it includes the ability to access the clipboard.

02-28-2007, 04:29 AM
Thanks, SORRY, I think I was looking on the wrong place in the the Website, That was just what I was looking for:D

02-28-2007, 04:57 AM
How to make it a button not a text ( the clickable text),

02-28-2007, 05:11 AM
Simply change this:

<a class="highlighttext" href="javascript:HighlightAll('test.select1')">Select All</a>

to this:

<a class="highlighttext" href="javascript:HighlightAll('test.select1')"><img src="image.gif"></a>

Hope this helps.

02-28-2007, 06:41 AM
actually I am looking for something like

<BUTTON type="button" OnClick="href="javascript:HighlightAll ('test2.select1'" style="width:70px;height:20px;z-index:2">

not a gif
also i tried your code it is giving me error

02-28-2007, 07:35 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">

Select and Copy form element script- By Dynamicdrive.com
For full source, Terms of service, and 100s DTHML scripts
Visit http://www.dynamicdrive.com

//specify whether contents should be auto copied to clipboard (memory)
//Applies only to IE 4+
//0=no, 1=yes
var copytoclip=1

function HighlightAll(theField) {
var tempval=eval("document."+theField);
if (document.all&&copytoclip==1&&tempval.createTextRange){
window.status="Contents highlighted and copied to clipboard!"


<form action="#" name="test2">
<input type="button" onclick="HighlightAll ('test2.select1')" style="width:70px;height:20px;z-index:2;" value="Select All"><br>
<textarea name="select1" cols="50" rows="5" wrap="virtual">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Fusce luctus turpis. Proin a lacus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed non purus in tellus semper porta. Praesent vel quam nec orci mollis dignissim. Nulla ultrices, tellus quis semper pretium, eros augue eleifend risus, at dictum massa urna blandit metus. Nullam libero metus, scelerisque in, sollicitudin in, tristique nec, tortor. Sed eu felis. Integer rutrum mauris id nisl. Praesent cursus. Vivamus faucibus.</textarea>

02-28-2007, 08:27 AM
Thats great, It looks much better, You are great