Results 1 to 3 of 3

Thread: Select (and copy) Form Element Script

  1. #1
    Join Date
    May 2007
    Location
    Mythica
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Select (and copy) Form Element Script

    1) Script Title: Select (and copy) Form Element Script

    2) Script URL (on DD):
    http://www.dynamicdrive.com/dynamici...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?????

    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>
    Code:
    <!--###### 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>

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    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:

    Code:
    <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.

  3. #3
    Join Date
    May 2007
    Location
    Mythica
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thank you so much, it is working great now

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •