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

Return selected text in textarea/text box

P: 2

I was just wondering if there is a way to return the highlighted text in a text box or a text area.

For instance:
<textarea id="foo"> The quick brown fox jumped ... </textarea>
<input type=text id="foo" value="The quick brown fox jumped ... ">

Lets say I highlight the text 'brown fox' in one of those fields, is there a way for me to get that text and say, for instance, copy to clipboard without using the mouse menu etc..

I get the copy to the clipboard part and tried document.getSelection() in mozilla
doesnt, and it doesnt seem to work for form fields. I'd be very thankful to anyone who has a solution to this.

Thanks in advance.
Jun 22 '08 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 15k+
P: 16,027
See this link for starters. Oh, and you can't have two elements with the same ID.
Jun 22 '08 #2

P: 2
Great that is just what I needed! :)

Oh, and you can't have two elements with the same ID.
Right, it was more like textarea or text box, anyway thanks for pointing it out.
Jun 22 '08 #3

Expert Mod 15k+
P: 16,027
Oh, I see, nvm.

Anyway, glad to see the link helped. If you have more questions, post again.

PS. I noticed that you've just joined, so here's a "welcome to Bytes!" Hope you enjoy your stay ;)
Jun 23 '08 #4

Post your reply

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