SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    Don't eat yellow snow spaceman's Avatar
    Join Date
    Mar 2001
    Location
    Melbourne, Australia
    Posts
    1,039
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need javascript so that I can click once on a block of text and all is selected

    Hello,

    If got a situation where I want to put a list of words or phrases on a page. When the user clicks anywhere on one of the words or phrases, the word or phrase should be highlighted so that the user can then copy and paste the word or phrase somewhere else.

    I'm sure I've seen this on a web page before, but can't remember where or when.

    I'd appreciate someone's help here. If it makes it easier, it's fine if each separate word or phrase is displayed inside it's own <INPUT> or <TEXTAREA>.

    Thanks very much.
    Web Design Perth Melbourne .:. Itomic Business Website Solutions
    Drupal Experts .:. Drupalise

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well i think there's a Method in the dom to allow for this.

    If you just have it like this:

    Code:
    <span class="Normal" current_clipboard=0 onclick="copyMe();">This is an example of some text</span>
    
    <textarea id="pending" style="display:none;"></textarea>
    
    <script language="Javascript">
    current_selection=0;
    function copyMe(){
            iSrc=window.event.srcElement;
            if (!iSrc.current_clipboard){ return null; }
            else {
                    if (current_selection) current_selection.style.color='whatever is normal';
                    current_selection=iSrc;
                    iSrc.style.color='#000099';
                    pending.innerTEXT=iSrc.innerTEXT;
                    Send=pending.createTextRange();
                    Send.execCommand('Copy');
                    }
            }
    </script>
    Couple of things to note:
    1) this may not work - i haven't tested it and it's only a thought
    2) i only write for ie 5+ - if you want it to be compliant with other browsers i'm sure Andrew or one of the others will love to correct me

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  3. #3
    SitePoint Member
    Join Date
    Jun 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this within a form
    <textarea rows="5" cols="50" name="yourname" onFocus="this.form.yourname.select();">
    Danny Mc Neill

  4. #4
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what ARE you on about?
    Have a look at the select() method - it doesn't copy anything!

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  5. #5
    SitePoint Member
    Join Date
    Jun 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Re-read the original question.
    so that the user can then copy and paste the word or phrase then copy and paste...
    That what I'm on about.
    Danny Mc Neill

  6. #6
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good point.

    I don't think we should be limited to that though!

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  7. #7
    SitePoint Member
    Join Date
    Jun 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think we should be limited to that though!
    Agreed - it would have a lot of useful applications.
    Danny Mc Neill

  8. #8
    SitePoint Member
    Join Date
    Jun 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This has just been pointed out to me -
    http://www.dynamicdrive.com/dynamicindex11/copytext.htm
    It should do what you want, Spaceman.
    Danny Mc Neill


Bookmarks

Posting Permissions

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