Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Well guys, i was just doing a simple stuff of executing system copy, delete etc. commands using execCommand method of js.

I have made two textareas, in one i am inputting some text and by hitting on the buttons i am executing copy, cut etc. commands.
Problems::::----
In this the paste button is not working. Like i am copying some text from one textarea, it is not pasting into other textarea.

Also I want to do select all for the textareas only. Like if cursor is on textarea1 and if I am hitting on selectAll button it should only select the textarea1 content. Currently it is selecting the whole page content.

Following is my code

HTML
 <html>
 <head>
  <script language="javascript">
   function doCopy()
   {
       document.execCommand('Copy',false,0);
   }
   function doPaste()
   {
       document.execCommand('Paste');
   }
   function doCut()
   {
       document.execCommand('Cut',false,0);
   }
   function doSelectAll()
   {
       document.execCommand('SelectAll',false,0);
   }
   function doDelete()
   {
       document.execCommand('Delete',false,0);
   }
   function doUndo()
   {
       document.execCommand('Undo',false,0);
   }
   function doUnselect()
   {
       document.execCommand('Unselect',false,0);
   }
  </script>
 </head>
 <body>
  <div align="center">
  input values : ---- <br>
  <textarea align="left" id="txtArea" name="txtArea" style="width:300px;height:50px"></textarea>
  <br>
  <input type="button" id="btnCopy" name="btnCopy" value=" Copy " onClick="doCopy()" />
  <input type="button" id="btnCut" name="btnCut" value=" Cut " onClick="doCut()" />
  <input type="button" id="btnSelectAll" name="btnSelectAll" value=" Select All " onClick="doSelectAll()" />
  <input type="button" id="btnPaste" name="btnPaste" value=" Paste " onClick="doPaste()" />
  <input type="button" id="btnDelete" name="btnDelete" value=" Delete " onClick="doDelete()" />
  <input type="button" id="btnUndo" name="btnUndo" value=" Undo " onClick="doUndo()" />
  <input type="button" id="btnUnselect" name="btnUnselect" value=" Undo " onClick="doUnselect()" />
  <br>
  Manipulate <br>
  <textarea align="left" id="txtArea1" onpaste="alert('yes');" name="txtArea1" style="width:300px;height:70px" ></textarea>
  </div>
 </body>
</html>




This stuff is for IE9.

Thanks

Arvind
Posted
Updated 19-Dec-11 0:11am
v2

1 solution

try this this code is for IE...

JavaScript
 <script language="javascript">
    function doCopy()
   {
        document.execCommand('Copy',false,0);
   }
   function doPaste()
   {
        document.execCommand('Paste');
   }
   function doCut()
   {
        document.execCommand('Cut',false,0);
   }
   function doSelectAll()
   {
        document.execCommand('SelectAll',false,0);
    }
  function doDelete()
   {
        document.execCommand('Delete',false,0);
   }
    function doUndo()
    {
        document.execCommand('Undo',false,0);
    }
    function doUnselect()
    {
        document.execCommand('Unselect',false,0);
    }
  </script>
 </head>
<body>
<div align="center">
  input values : ---- <br>
 <textarea align="left" id="txtArea" name="txtArea" style="width:300px;         height:50px"></textarea>
 <br>
  <input type="button" id="btnCopy" name="btnCopy" value=" Copy "  önclick="doCopy()" />
  <input type="button" id="btnCut" name="btnCut" value=" Cut "  önclick="doCut()" />
  <input type="button" id="btnSelectAll" name="btnSelectAll" value=" Select All "  önclick="doSelectAll()" />
  <input type="button" id="btnPaste" name="btnPaste" value=" Paste "  önclick="doPaste()" />
  <input type="button" id="btnDelete" name="btnDelete" value=" Delete "  önclick="doDelete()" />
 <input type="button" id="btnUndo" name="btnUndo" value=" Undo "  önclick="doUndo()" />
 <input type="button" id="btnUnselect" name="btnUnselect" value=" Undo "  önclick="doUnselect()" />
  <br>
  Manipulate <br>
  <textarea align="left" id="txtArea1"  önpaste="alert('yes');" name="txtArea1" style="width:300px;height:70px" ></textarea>
   </div>
 
Share this answer
 
v2
Comments
RaviRanjanKr 20-Dec-11 5:22am    
5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900