By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,509 Members | 1,301 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,509 IT Pros & Developers. It's quick & easy.

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

P: 11
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
Dec 1 '09 #1
Share this Question
Share on Google+
7 Replies


RamananKalirajan
100+
P: 607
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
Dec 1 '09 #2

P: 11
Ok..
Is it possible to select entire text using double/single click in output text?
If so pls give me reply.
Dec 1 '09 #3

RamananKalirajan
100+
P: 607
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

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     function selectText(textC) 
  3. {
  4. if (document.selection)
  5. {
  6. //Portion for IE
  7. var div = document.body.createTextRange();
  8. div.moveToElementText(textC);
  9. div.select();
  10. }
  11. else
  12. {
  13. //Portion for FF
  14. var div = document.createRange();
  15. div.setStartBefore(textC);
  16. div.setEndAfter(textC);
  17. window.getSelection().addRange(div);
  18. }
  19. }
  20. </script>
HTML Code
Expand|Select|Wrap|Line Numbers
  1. <p onclick="selectText(this);">
  2.     aslf;sdkfaslkmdfasd
  3.     sdfasd
  4.     fasdsadf
  5.     asd
  6.     fasd
  7.     fasd
  8.     fasdfasdfasdf
  9. </p>
Thanks and Regards
Ramanan Kalirajan
Dec 2 '09 #4

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

RamananKalirajan
100+
P: 607
Hi,
I dont have any idea regarding JSF, can you use Div instead of <p>

Thanks and Regards
Ramanan Kalirajan
Dec 2 '09 #6

P: 11
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??
Dec 2 '09 #7

RamananKalirajan
100+
P: 607
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
Expand|Select|Wrap|Line Numbers
  1. <div onclick="selectText(this)">
  2.     <span ondblclick="selectText(this)">
  3.     </span>
  4.     <span ondblclick="selectText(this)">
  5.     </span>
  6.     <span ondblclick="selectText(this)">
  7.     </span>
  8.     <span ondblclick="selectText(this)">
  9.     </span>
  10. </div>
Thanks and Regards
Ramanan Kalirajan
Dec 2 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.