How to select text which is in multiple lines on clicking more than twice?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chaitanya83
    New Member
    • Dec 2009
    • 11

    How to select text which is in multiple lines on clicking more than twice?

    How to select text which is in multiple lines on clicking more than twice?

    I have scenario like this:

    eg:-6118051
    Non-Receipt
    Per web, delivery incomplete. Request trace and driver followup for delivery details. Otherwise please provide explanation for claim # authorization.

    Last scan: Sep 21, 2009 6:13 PM Left FedEx origin facility UNION CITY, CA


    Assume u have this text.If I double click on any word only that word has to select.
    If i click more than twice whole text hast to select
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    It's browser property you cant change those things. Some browser will work as you expected. Even if you are trying with JS you have only single click and double click listener.

    Thanks and Regards
    Ramanan Kalirajan

    Comment

    • chaitanya83
      New Member
      • Dec 2009
      • 11

      #3
      Ok..
      Is it possible to select entire text using double/single click in output text?
      If so pls give me reply.

      Comment

      • RamananKalirajan
        Contributor
        • Mar 2008
        • 608

        #4
        You can give the text inside the <p> and have a onclick listener so that onclick of the <p> you can select the whole paragraph

        Ex.. JS Code

        Code:
        <script type="text/javascript">
        	function selectText(textC) 
        {
        if (document.selection)
        {
        //Portion for IE
        var div = document.body.createTextRange();
        div.moveToElementText(textC);
        div.select();
        }
        else
        {
        //Portion for FF
        var div = document.createRange();
        div.setStartBefore(textC);
        div.setEndAfter(textC);
        window.getSelection().addRange(div);
        }
        }
        </script>
        HTML Code
        Code:
        <p onclick="selectText(this);">
        	aslf;sdkfaslkmdfasd
        	sdfasd
        	fasdsadf
        	asd
        	fasd
        	fasd
        	fasdfasdfasdf
        </p>
        Thanks and Regards
        Ramanan Kalirajan

        Comment

        • chaitanya83
          New Member
          • Dec 2009
          • 11

          #5
          Hi,
          Thanks for ur solution.
          This I have to implement in JSF.
          I can't keep in paragraph.
          Do u have idea about JSF??

          Comment

          • RamananKalirajan
            Contributor
            • Mar 2008
            • 608

            #6
            Hi,
            I dont have any idea regarding JSF, can you use Div instead of <p>

            Thanks and Regards
            Ramanan Kalirajan

            Comment

            • chaitanya83
              New Member
              • Dec 2009
              • 11

              #7
              Hi...If I keep in div it is working fine.

              But i want another scenario also..On single click whole text is getting selected..this is fine

              when I double click on part of text only that part has to select.

              Is it possible to do both??

              Comment

              • RamananKalirajan
                Contributor
                • Mar 2008
                • 608

                #8
                Yep this is possible you can have many span inside the div and write a double click events for that span and a single click event for the div. This is a suggestion, you can try that..

                Pseudocode
                Code:
                <div onclick="selectText(this)">
                    <span ondblclick="selectText(this)">
                    </span>
                    <span ondblclick="selectText(this)">
                    </span>
                    <span ondblclick="selectText(this)">
                    </span>
                    <span ondblclick="selectText(this)">
                    </span>
                </div>
                Thanks and Regards
                Ramanan Kalirajan

                Comment

                Working...