Web Analytics Made Easy -
StatCounter Paste Function [Resolved] - CodingForum

Announcement

Collapse
No announcement yet.

Paste Function [Resolved]

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Paste Function [Resolved]

    Hi,

    I am trying to write custom Select All, copy, cut and paste functions which I intend to access from a custom context menu

    However I can't get the paste function to work it replaces everything in the textarea rather than 1. the selected text or 2. insert at the cursor location

    Code:
    <html>
    <head>
    <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=0
    
    function HighlightAll(theField) {
    	var tempval=eval("document."+theField)
    	tempval.focus()
    	tempval.select()
    	if (document.all&&copytoclip==1){
    		therange=tempval.createTextRange()
    		therange.execCommand("Copy")
    	}
    }
    
    var copiedtext=""
    var tempstore=""
    
    function Copy() {
    	if (document.all){
    		tempstore=copiedtext
    		document.execCommand("Copy")
    		copiedtext=window.clipboardData.getData("Text");
    	}
    }
    
    function Cut() {
    	if (document.all){
    		tempstore=copiedtext
    		document.execCommand("Cut")
    		copiedtext=window.clipboardData.getData("Text");
    	}
    }
    
    [b]function Paste(theField) {
    	var tempval=eval("document."+theField)
    	if (document.all){
    		therange=tempval.createTextRange()
    		therange.execCommand("Paste")
    	}
    }[/b]
    //-->
    </script>
    </head>
    <body>
    <form name="test">
    <a class="highlighttext" href="javascript:HighlightAll('test.select1')">Select All</a> |
    <a class="highlighttext" href="javascript:Copy()">Copy</a> |
    <a class="highlighttext" href="javascript:Cut()">Cut</a> |
    <a class="highlighttext" href="javascript:Paste('test.select1')">Paste</a>
    <br />
    <textarea name="select1" rows="10" cols="35" >This is some text. This is some text. This is some text. This is some text.</textarea>
    </form>
    <p>The Paste function is not complete, it replaces everything in the textarea rather than the selected text or insert at the cursor location
    </p>
    </body>
    </html>
    Can anyone see what the problem is and how to fix it?

    Regards Allan
    Last edited by Running Bear; Aug 3, 2005, 04:25 AM. Reason: hi-light Paste function, resolved

  • #2
    Code:
    function Paste(theField) {
    	var tempval=eval("document."+theField)
    	if (document.all){
    		tempval.focus()
    		document.execCommand("Paste")
    	}
    }
    - John

    Comment


    • #3
      jscheuer1,

      Thanks a whole bunch for that, it looks to be spot on

      Cheers Al

      Comment

      Working...
      X