Results 1 to 6 of 6

Thread: getselection() - textselection?

  1. #1
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default getselection() - textselection?

    I know how to use this function...
    But I only want this function to work on a textarea...
    How would I do that!? Also I've tried like document.textname and also getElementById please help!
    Jeremy | jfein.net

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    No one?
    Jeremy | jfein.net

  3. #3
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    http://www.squarefree.com/2006/05/06...rea-selection/

    Looks like you'll have to have browser specific code as there are different techniques for IE vs Firefox

  4. The Following User Says Thank You to Medyman For This Useful Post:

    Nile (03-02-2008)

  5. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Thanks So Much!
    But when I do selectionEnd it just prints out how many characters I put..
    Last edited by Nile; 03-02-2008 at 06:13 PM.
    Jeremy | jfein.net

  6. #5
    Join Date
    Mar 2008
    Posts
    12
    Thanks
    0
    Thanked 5 Times in 4 Posts

    Default

    Why don't you explicitly say for which browser you need which functionality?
    You have already been given a hint that there are major differences between the different browsers' implementations of the selection mechanism...

  7. #6
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    this code will check what text is selected in the text box every .2 seconds and output it to a span.
    Code:
    <span id="output">No Text Selected</span>
    <hr>
    <form action="#" method="get">
    <textarea id="select" cols="40" rows="5">1234567890
    abcdefghijklmnopqrstuvwxyz</textarea><br>
    </form>
    <script type="text/javascript">
    var int=setInterval(check, 200);
    function check() { document.getElementById("output").innerHTML = getSelectionInfo(); }
    
    function getSelectionInfo()
    {
      var rv = "";
      var x;
      x = document.getElementById("select");
      if(!document.selection) { //if not IE
    	rv = x.value.substr(x.selectionStart, x.selectionEnd - x.selectionStart);
      } else {
    	rv = document.selection.createRange().text;
      }
      if (rv == null || rv == "") {
    	rv="No Text Selected";
      }
      	return rv;
    }
    
    </script>
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@ /\/\@|{
    There are 10 kinds of people in the world, those that understand binary and those that don't.

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
  •