PDA

View Full Version : select all for text in text box



mailtosaleh
02-28-2007, 02: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 )

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

http://www.dynamicdrive.com/dynamicindex11/selectform.htm

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

Hope this helps.

jscheuer1
02-28-2007, 03: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:


element.focus();
element.select();

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:

http://codingforums.com/showthread.php?t=65106

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

http://www.ms-inc.net/ViewThread.aspx?ThreadID=169

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

mailtosaleh
02-28-2007, 03: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

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

thetestingsite
02-28-2007, 04: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.

mailtosaleh
02-28-2007, 05: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
TKS

jscheuer1
02-28-2007, 06:35 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<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);
tempval.focus();
tempval.select();
if (document.all&&copytoclip==1&&tempval.createTextRange){
therange=tempval.createTextRange()
if(therange.execCommand)
therange.execCommand("Copy")
else
return;
window.status="Contents highlighted and copied to clipboard!"
setTimeout("window.status=''",1800)
}
}

</script>

</head>
<body>
<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>
</form>
</body>
</html>

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