PDA

View Full Version : Select (and copy) Form Element Script



SilverWolf
12-11-2007, 02:01 AM
1) Script Title: Select (and copy) Form Element Script

2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex11/selectform.htm

3) Describe problem: For some reason I am unable to get highlight to activate when I press "select all". Am I missing some thing? A piece of code?????


<style>
.highlighttext{
background-color:yellow;
font-weight:bold;
}
</style>

<script language="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){
therange=tempval.createTextRange()
therange.execCommand("Copy")
window.status="Contents highlighted and copied to clipboard!"
setTimeout("window.status=''",1800)
}
}
//-->
</script>



<!--###### egg 1######### -->
<img src="xxxx" border="0"></img><br>

<form name="Egg1">
<a class="highlighttext" href="javascript:HighlightAll('test.select1')">Select All</a><br>
<textarea name="select1" rows=8 cols=45>This is some text. This is some text. This is some text. This is some text.</textarea>
</form><br>

<img src="bar1.png" border="0"><br><br>

<!--###### egg 2 ######### -->
<img src="xxxx" border="0"></img><br>

<form name="Egg2">
<a class="highlighttext" href="javascript:HighlightAll('test.select2')">Select All</a><br>
<textarea name="select2" rows=8 cols=45 >This is some text. This is some text. This is some text. This is some text.</textarea>
</form><br>

<img src="bar1.png" border="0"><br><br>

<!--###### egg 3 ######### -->

<img src="xxxx" border="0"></img><br>

<form name="Egg3">
<a class="highlighttext" href="javascript:HighlightAll('test.select3')">Select All</a><br>
<textarea name="select3" rows=8 cols=45 >This is some text. This is some text. This is some text. This is some text.</textarea>
</form><br>

ddadmin
12-11-2007, 11:32 PM
You need to make sure your form's name is passed into the select function correctly, instead of the default name used in the demo. For example:


<form name="Egg1">
<a class="highlighttext" href="javascript:HighlightAll('Egg1.select1')">Select All</a><br>
<textarea name="select1" rows=8 cols=45>This is some text. This is some text. This is some text. This is some text.</textarea>
</form><br>

Notice how the two parts in red should match.

SilverWolf
12-12-2007, 12:35 AM
Thank you so much, it is working great now