Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to select words in textarea but not on page??

Status
Not open for further replies.

mart28

Programmer
Mar 11, 2002
2
CA
How do you stop the user from selecting any text on a page but still allow them to select text in textarea for editing purposes? At the moment I am using onselectstart="return false" in the body tag but it also stops you selecting any text in textareas too.
 
Hi Mart28,

Try this:

<SCRIPT language=&quot;JavaScript&quot;>
function SelectTrue()
{
window.event.cancelBubble = true;
window.event.returnValue = true;
}
</SCRIPT>


<body onselectstart=&quot;return false&quot;>

<FORM onselectstart=&quot;SelectTrue()&quot; name=&quot;FormName&quot; METHOD=&quot;POST&quot; >

Hope this helps,
Erik

<!-- My sport: Boomerang throwing !!
This year I will participate at the World Championships in Germany. (!! Many Happy Returns !! -->
 
Maybe I was a bit confusing. In my first post the whole <form> is allowed to be selected.
(I assumed that the textarea is in the form)

I you only use a Textarea or if you only want the Textarea in a form to be selected , then put the function in the Textarea:

<TEXTAREA onselectstart=&quot;SelectTrue()&quot;

Hope this helps,
Erik <!-- My sport: Boomerang throwing !!
This year I will participate at the World Championships in Germany. (!! Many Happy Returns !! -->
 
Thankyou for the tip. It's now working great thanks to your second post.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top