Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Auto Copy Contents Of A Hidden Text Area
Old 11-18-2009, 12:32 AM Auto Copy Contents Of A Hidden Text Area
Novice Talker

Posts: 7
Name: Kevin
Trades: 0
Hi guys,

I have been working on a page which allows me to click a button which then in turn copies the contents of a textarea. I have placed the script below into my Header section.


<script language='Javascript'>
function doact(d)
{
var doc = eval("document.readme."+d);
cp = doc.createTextRange();
doc.focus();
doc.select();
cp.execCommand("Copy");
}
</script>
<form name="readme">


In my Body I am using the following:

<textarea name="text1" cols="1" rows="1" style="display:all">Some Text</TEXTAREA>
<input onclick="doact('text1')" type="button" value="Host Headers">

The problem I am having is when I change the display type to hidden the copy function doesnt work. I do not wish to have the textarea displayed on my site as it is simply used to quickly copy proformas etc.

Any Ideas

Last edited by RiverAce; 11-18-2009 at 12:38 AM.. Reason: fault
RiverAce is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-18-2009, 06:17 AM Re: Auto Copy Contents Of A Hidden Text Area
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
there is no display:all or display:hidden

display
visibility
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-18-2009, 07:58 AM Re: Auto Copy Contents Of A Hidden Text Area
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
****, I was sure I had replied this morning...
Chris, the "copy to clipboard" is IE only anyway, so don't bother too much on css compliance

As for RiverAce, try this:
HTML Code:
<html>

<body>
    <script language='Javascript'>
    function doact(elm){
        cp = elm.createTextRange();
        cp.execCommand("Copy");
    }
    </script>
    
    <form name="frm" method="post">
        <textarea id="text1" name="text1" cols="100" rows="100" style="display:none">Some Text lala</TEXTAREA>
    <input onclick="doact(document.getElementById('text1'))" type="button" value="Host Headers">
    </form>
</body>

</html>
My guess would be that you cannot focus() a hidden element, and that the script stops there.
But, as it's IE, it's almost impossible to debug (I mean, real debug, with breakpoints, stack trace, watches and such!).
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 11-18-2009 at 08:04 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-19-2009, 02:58 AM Re: Auto Copy Contents Of A Hidden Text Area
Novice Talker

Posts: 7
Name: Kevin
Trades: 0
Legend

Thanks a ton for that.

I beleive their are a number of forums out their with this same issue. This thread beats them all. cheers
RiverAce is offline
Reply With Quote
View Public Profile
 
Old 11-24-2009, 10:59 PM Re: Auto Copy Contents Of A Hidden Text Area
Novice Talker

Posts: 7
Name: Kevin
Trades: 0
I dont suppose you would know how to incorporate this into a drop down menu.

For example select a text area through a drop down and have a single copy button to copy the text within that text area.

This would mean I could select a proforma from a drop down and have a single button to copy to the clipboard.
RiverAce is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Auto Copy Contents Of A Hidden Text Area
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.61360 seconds with 12 queries