spacer
Yehuda Shiran October 21, 2001
Detecting a Selection
Tips: October 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Linux Subscriptions Paying Off for Red Hat
OpenVAS Charts Its Own Forked Course
A Linux Year in Review: Sun's Very Big Buy
Although Netscape Navigator 4.x and Netscape 6 cannot retrieve the text of a selection within a text or textarea field, they can respond to one. Both Netscape browsers feature the onselect event handler that executes JavaScript code when the user selects some of the text within a form's field. This event handler cannot be used for other elements on the page. Try entering text in the field below and then select a portion of it with a mouse movement:

Enter your text and select it:

Here is how the form above is defined:

<FORM>
Enter your text and select it: <INPUT TYPE="text" NAME="data" SIZE="30"
       onSelect="alert('text selected')">
</FORM>
The onselect event handler is also supported by Internet Explorer as an event handler of text and textarea fields. This event does not bubble like most other events in Internet Explorer. Events that do not bubble can only be handled on the individual object that fired the event, so you cannot capture select events at the document level. Try the above selection exercise in both Netscape 6 (or Navigator 4.x) and Internet Explorer. You can observe a noticeable difference. Netscape 6 (as well as Navigator 4.x) reacts to the event's completion, when the mouse button is being released. Internet Explorer, though, reacts to the event's initiation, when the mouse button is being pressed.

See Column 10 (The Internet Explorer Event Model) for a complete discussion of the Internet Explorer event model, and Column 11 (The Cross Browser Event Model) for the cross-browser event model.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Email Marketing Terms to Know · Search Engines 101: Paid Vs. Natural Search · Web 2.0 Tools
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Connecticut Town Lays Groundwork for Merged School, Municipal VoIP Network · Case Study: Leveraging Next-Gen Wi-Fi to Transform Healthcare · Tripp Lite Announces Five New Surge Suppressors