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 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Smile Javascript multiple copy to clipboard issue

    hi I was wondering if someone could help me, i'm trying to create a simple webpage page that copies predefined text via the command buttons.

    I cannot for the life of me figure out how to get the txtbox1 value to get copied to the clipboard?! txtbox2 works perfectly though? Please can someone help:

    Code:
    <script  type="text/javascript">
    
    function ClipBoard() 
    {
    window.clipboardData.setData("Text",document.links.txtbox1.value);
    }
    
    function ClipBoard() 
    {
    window.clipboardData.setData("Text",document.links2.txtbox2.value);
    }
    </script>
    
    
    
    <form name="links">
    <input type="text"  name="txtbox1" class="formtext" onclick="highlight(this)" style="width: 400px" size="70" value="Hello one:" /><br />
    <BUTTON onclick="ClipBoard()">Copy1</BUTTON>
    </form>
    
    
    <form name="links2">
    <input type="text"  name="txtbox2" class="formtext" onclick="highlight(this)" style="width: 400px" size="70" value="Hello two:" /><br />
    <BUTTON onclick="ClipBoard()">Copy2</BUTTON>
    </form>
    Thank you

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    You can't have two functions with the same name. The second one is overwriting the first.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • Users who have thanked WolfShade for this post:

    javascriptnoob1 (10-23-2012)

  • #3
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by WolfShade View Post
    You can't have two functions with the same name. The second one is overwriting the first.

    hello WolfShade,

    Thank you for helping me, I have changed the name and still cannot get the coding to work:

    Code:
    <script  type="text/javascript">
    
    function ClipBoard() 
    {
    window.clipboardData.setData("Text",document.links.txtbox1.value);
    }
    
    function ClipBoard2() 
    {
    window.clipboardData2.setData("Text",document.links2.txtbox2.value);
    }
    </script>
    please can you help?

  • #4
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Did you also change the second BUTTON to the new function name?
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • Users who have thanked WolfShade for this post:

    javascriptnoob1 (10-23-2012)

  • #5
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by WolfShade View Post
    Did you also change the second BUTTON to the new function name?
    i've changed that also and it still does not work??

    Code:
    <script  type="text/javascript">
    
    function ClipBoard() 
    {
    window.clipboardData.setData("Text",document.links.txtbox1.value);
    }
    
    function ClipBoard2() 
    {
    window.clipboardData2.setData("Text",document.links2.txtbox2.value);
    }
    </script>
    
    
    <form name="links">
    <input type="text"  name="txtbox1" class="formtext" onclick="highlight(this)" style="width: 400px" size="70" value="Hello one:" /><br />
    <BUTTON onclick="ClipBoard()">Copy1</BUTTON>
    </form>
    
    
    <form name="links2">
    <input type="text"  name="txtbox2" class="formtext" onclick="highlight(this)" style="width: 400px" size="70" value="Hello two:" /><br />
    <BUTTON onclick="ClipBoard2()">Copy2</BUTTON>
    </form>

  • #6
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    What is clipboardData???
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • Users who have thanked WolfShade for this post:

    javascriptnoob1 (10-23-2012)

  • #7
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by WolfShade View Post
    What is clipboardData???
    it works

    Thank you so much!, here is the coding for those of you that are interested:

    Code:
    <script  type="text/javascript">
    
    function ClipBoard() 
    {
    window.clipboardData.setData("Text",document.links.txtbox1.value);
    }
    
    function ClipBoard2() 
    {
    window.clipboardData.setData("Text",document.links2.txtbox2.value);
    }
    </script>
    
    
    <form name="links">
    <input type="text"  name="txtbox1" class="formtext" onclick="highlight(this)" style="width: 400px" size="70" value="Hello one:" /><br />
    <BUTTON onclick="ClipBoard()">Copy1</BUTTON>
    </form>
    
    
    <form name="links2">
    <input type="text"  name="txtbox2" class="formtext" onclick="highlight(this)" style="width: 400px" size="70" value="Hello two:" /><br />
    <BUTTON onclick="ClipBoard2()">Copy2</BUTTON>
    </form>
    Last edited by javascriptnoob1; 10-23-2012 at 03:29 PM.

  • #8
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Quote Originally Posted by WolfShade View Post
    What is clipboardData???
    i had to google that too lol. looks to be proprietary to ie. I found a good discussion here : http://stackoverflow.com/questions/2...-cross-browser

  • #9
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    So it will only work in IE????
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #10
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Quote Originally Posted by WolfShade View Post
    So it will only work in IE????
    looks that way to me. in that thread there is mention of capturing text from the paste event which is what ckeditor and some others do, but there are limitations there as well


  •  

    Posting Permissions

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