Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts

    button onclick copy the text in textarea

    hi,

    i have 3 textareas and 3 buttons on a page.when i click the particular button the text inside the textarea should be copied.it is working but when i keep this in a for loop,it is not working

    iam using the following code.but when i click button and paste the text it displays 'undefined'.not copyin the text.any of your help will be appreciated
    thanks
    mrjameer

    <?php
    for($i=0;$i<=3;$i++)
    {
    ?>
    <textarea name="copytext1">ABCD</textarea><BUTTON onClick="ClipBoard1();">Copy to Clipboard</BUTTON> <br>
    <textarea name="copytext2">EFGH</textarea><BUTTON onClick="ClipBoard2();">Copy to Clipboard</BUTTON> <br>
    <textarea name="copytext3">IJKL</textarea><BUTTON onClick="ClipBoard3();">Copy to Clipboard</BUTTON> <br>

    <?php
    }
    ?>


    <TEXTAREA ID="holdtext" STYLE="display:none;">
    </TEXTAREA>


    <SCRIPT LANGUAGE="JavaScript">

    function ClipBoard1()
    {
    holdtext.innerText = copytext1.innerText;
    Copied = holdtext.createTextRange();
    Copied.execCommand("Copy");
    }
    function ClipBoard2()
    {
    holdtext.innerText = copytext2.innerText;
    Copied = holdtext.createTextRange();
    Copied.execCommand("Copy");
    }
    function ClipBoard3()
    {
    holdtext.innerText = copytext3.innerText;
    Copied = holdtext.createTextRange();
    Copied.execCommand("Copy");
    }
    </SCRIPT>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    lol,

    putting the code

    Code:
    <textarea name="copytext1">ABCD</textarea><BUTTON onClick="ClipBoard1();">Copy to Clipboard</BUTTON> <br>
    <textarea name="copytext2">EFGH</textarea><BUTTON onClick="ClipBoard2();">Copy to Clipboard</BUTTON> <br>
    <textarea name="copytext3">IJKL</textarea><BUTTON onClick="ClipBoard3();">Copy to Clipboard</BUTTON> <br>
    means your final document would have 12 such textareas, duplicated their names
    4 times, you are not allowed to do so. isn't it?
    Try to validate your final page source using w3validator

    regards,
    art
    Last edited by abduraooft; 07-05-2007 at 02:45 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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