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

selected text

P: 1
i want to get the seleted text from textbox either in vbscript,java script or in asp.net. can anyone help me to find this
Feb 7 '07 #1
Share this Question
Share on Google+
4 Replies

acoder
Expert Mod 15k+
P: 16,027
Welcome to The Scripts.

Use the following code to get the selected text from a text box:
Expand|Select|Wrap|Line Numbers
  1. var sel = (txt.value).substring(txt.selectionStart,txt.selectionEnd);
where txt is the text box object.
Feb 7 '07 #2

dmjpro
100+
P: 2,476
in which browser u r talking..
i tried in ie 6.0 it didn't work
plz send me ur reply
i am online................
Feb 8 '07 #3

acoder
Expert Mod 15k+
P: 16,027
in which browser u r talking..
i tried in ie 6.0 it didn't work
plz send me ur reply
i am online................
It seems you have to use:
Expand|Select|Wrap|Line Numbers
  1. if (document.selection) {
  2.   txt = document.selection.createRange().text;
  3. }
  4.  
See this page.
So I guess the code I provided wasn't cross-browser compatible. Use the code on that page to support all browsers.
Feb 8 '07 #4

dmjpro
100+
P: 2,476
now u r right ..........
thanks for ur reply
Feb 8 '07 #5

Post your reply

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