Cut & Paste

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simo

    Cut & Paste

    I use these two functions for Copy & Paste with buttons in some text area
    into a form:

    <SCRIPT LANGUAGE="Javas cript">

    function copy(area){
    var temp = eval("document. " + area);
    aa=temp;
    window.clipboar dData.setData(' Text',aa);
    }

    function paste(area2){
    var temp2 = eval("document. " + area2);
    bb=window.clipb oardData.getDat a('Text');
    temp2 = bb;
    }
    </SCRIPT>
    </head>


    If i call the Copy function (dinamically with php) with a parameter like:
    form1.text1.val ue it works fine, but with the Paste function doesn't work.
    I think the problem is in the evaluate statement of the parameter area2.

    Anyone can help me ?? Thanks

    Simone


  • Evertjan.

    #2
    Re: Cut &amp; Paste

    Simo wrote on 28 apr 2004 in comp.lang.javas cript:
    [color=blue]
    > <SCRIPT LANGUAGE="Javas cript">
    >
    > function copy(area){
    > var temp = eval("document. " + area);
    > aa=temp;
    > window.clipboar dData.setData(' Text',aa);
    >}
    >
    > function paste(area2){
    > var temp2 = eval("document. " + area2);
    > bb=window.clipb oardData.getDat a('Text');
    > temp2 = bb;
    >}
    > </SCRIPT>
    >[/color]

    Try this:

    <div id=from>qwerty</div>
    =============== ============
    <div id=to>asdfg</div>

    <script type="text/javascript">

    function copy(area){
    var temp = document.getEle mentById(area);
    window.clipboar dData.setData(' Text',temp.inne rHTML);
    }

    function paste(area){
    var temp = document.getEle mentById(area);
    temp.innerHTML = window.clipboar dData.getData(' Text');
    }

    copy("from")
    paste("to")


    </script>

    Tested IE6

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • Brian Genisio

      #3
      Re: Cut &amp; Paste

      Simo wrote:
      [color=blue]
      > I use these two functions for Copy & Paste with buttons in some text area
      > into a form:
      >
      > <SCRIPT LANGUAGE="Javas cript">
      >
      > function copy(area){
      > var temp = eval("document. " + area);
      > aa=temp;
      > window.clipboar dData.setData(' Text',aa);
      > }
      >
      > function paste(area2){
      > var temp2 = eval("document. " + area2);
      > bb=window.clipb oardData.getDat a('Text');
      > temp2 = bb;
      > }
      > </SCRIPT>
      > </head>
      >
      >
      > If i call the Copy function (dinamically with php) with a parameter like:
      > form1.text1.val ue it works fine, but with the Paste function doesn't work.
      > I think the problem is in the evaluate statement of the parameter area2.
      >
      > Anyone can help me ?? Thanks
      >
      > Simone
      >
      >[/color]

      Wow... where do I start?

      1. Do not use LANGUAGE. Instead, use TYPE
      2. Do not use eval(). There are always better ways to do it
      3. Dont make so many temp variables. It makes it hard to read
      4. clipboardData only works in IE 5+. I dont know if anything like this
      exists in other browsers.

      Try something more like this. Of course, modify it for a better set of
      what you need, but this should give you a good start.

      -- Brian

      <HTML>
      <HEAD>
      <SCRIPT type="text/javascript">

      function copy(source){
      window.clipboar dData.setData(" Text",
      document.getEle mentById(source ).value);
      }

      function paste(dest){
      document.getEle mentById(dest). value =
      window.clipboar dData.getData(" Text");
      }

      function CopyAndPaste( from, to )
      {
      copy(from); paste(to);
      }

      </SCRIPT>
      </HEAD>

      <BODY>
      <FORM action="submit. asp">
      <INPUT TYPE=text name=text1>Text 1<BR>
      <INPUT TYPE=text name=text2>Text 2<BR>
      </FORM>

      <BUTTON onClick="CopyAn dPaste('text1', 'text2')">
      Copy and Paste
      </BUTTON>

      </BODY>
      </HTML>

      Comment

      • Mick White

        #4
        Re: Cut &amp; Paste

        Brian Genisio wrote:

        [color=blue]
        > 4. clipboardData only works in IE 5+. I dont know if anything like this
        > exists in other browsers.[/color]

        IE 5+ Windows!
        Mick.

        Comment

        Working...