Guest PocketLnt Posted March 31, 2006 Share Posted March 31, 2006 I'm looking for a way to programatically select certain text in a text control. In another words, I want to take a text control from a form and call a function which will give focus to that control and set an arbitrary number of characters to highlighted.Right now the select() method of the element is the closet thing I have found to accomplish this task, but it apparently only selects the entire text in the control. So what does everyone think, is this possible? Link to comment Share on other sites More sharing options...
SillyBilly Posted April 3, 2006 Share Posted April 3, 2006 I'm looking for a way to programatically select certain text in a text control. In another words, I want to take a text control from a form and call a function which will give focus to that control and set an arbitrary number of characters to highlighted.Right now the select() method of the element is the closet thing I have found to accomplish this task, but it apparently only selects the entire text in the control. So what does everyone think, is this possible?<{POST_SNAPBACK}> have you tried to google, parse text? Link to comment Share on other sites More sharing options...
raimo Posted April 3, 2006 Share Posted April 3, 2006 With this one You can get selected text from everywhere, should work with all browsers: function getSelected(){var s = '';if (window.getSelection) // Foxy + other lizards{s = window.getSelection();}else if (document.getSelection) // Opera{s = document.getSelection();}else if (document.selection) // MSIE{s = document.selection.createRange().text;}return s;} edit:sorry, You are selecting text out there, not getting selected text.I'd read Your post somehow wrong, but anyway You can get selected text asI mentioned. :)edit2:Look this:http://developer.mozilla.org/en/docs/DOM:Selection Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now