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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Posts
    682
    Thanks
    24
    Thanked 1 Time in 1 Post

    Auto Highlighting Code

    I've seen these buttons around the net where the user has to copy code in a window but instead of selecting all the code themselves with their mouse they can instead click a button under the code window that says something like "Highlight Code" & then all the code in the window is highlighted & they can eaisly copy it...

    How can you do this?

    Thanks!

  • #2
    Regular Coder
    Join Date
    Feb 2003
    Posts
    638
    Thanks
    0
    Thanked 0 Times in 0 Posts
    document.formName.elementName.select()
    hmm... ?

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Posts
    682
    Thanks
    24
    Thanked 1 Time in 1 Post
    So where do I put that code?

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <form><textarea name="textarea" cols="42" rows="12">
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec nibh lorem, pellentesque eget, gravida quis, hendrerit sit amet, elit. In molestie faucibus nunc. Suspendisse potenti. Cras eros odio, tincidunt at, iaculis non, tempor nec, dui. Pellentesque massa erat, adipiscing at, tempor nec, condimentum sit amet, magna. Vestibulum porttitor felis at quam. Nulla vel libero non ipsum tristique adipiscing. Maecenas consequat pretium ante. Vestibulum porta. Mauris congue velit vitae augue. Ut facilisis posuere erat. Aliquam interdum porta erat</textarea><br>
    <input type="button" value="Select"
    onclick="this.form.textarea.focus();
    this.form.textarea.select()"></form>

  • #5
    Regular Coder
    Join Date
    Apr 2004
    Posts
    682
    Thanks
    24
    Thanked 1 Time in 1 Post
    Thanks!

  • #6
    Regular Coder
    Join Date
    Feb 2003
    Posts
    638
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just the select() would probably do.
    Setting focus() doesn't seem necessary.
    hmm... ?

  • #7
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    For most instances you are probably right but for those times that the text to be highlighted is not currently in the viewport, setting focus would be better. Below is a brief example. If you try it with and without focus you will see the differences.

    Code:
    <form>
    <div style="height:1800px">
    <input type="button" value="Select"
    onclick="this.form.textarea.focus();this.form.textarea.select()"></div>
    
    
    <textarea name="textarea" cols="42" rows="12">
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec nibh lorem, pellentesque eget, gravida quis, hendrerit sit amet, elit. In molestie faucibus nunc. Suspendisse potenti. Cras eros odio, tincidunt at, iaculis non, tempor nec, dui. Pellentesque massa erat, adipiscing at, tempor nec, condimentum sit amet, magna. Vestibulum porttitor felis at quam. Nulla vel libero non ipsum tristique adipiscing. Maecenas consequat pretium ante. Vestibulum porta. Mauris congue velit vitae augue. Ut facilisis posuere erat. Aliquam interdum porta erat</textarea><br>
    </form>

  • #8
    Regular Coder
    Join Date
    Feb 2003
    Posts
    638
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Good point.
    hmm... ?


  •  

    Posting Permissions

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