NetAdminTools.com
 
SignalQ Sites:
NetAdminTools - Coprolite - NoNIC - SpotBridge - NAW
RoboCoop - AreWeDown - SolarPower - SysAdminTools
Xfig - Gold Loaf - GeekPapa - FixGMC - MCJ - FixRambler
Categories:
GNU/Linux | Homebrew designs | Perl | Administration | Backup/Recovery | Bugs/Fixes | Certification | Database | Email | File/Print | Hardware | Information Grab Bag | Interoperability | GNU/Linux ABCs | Monitoring | Name Resolution | Network Services | Networking | Remote Control | Security | Desktop | Web | BSD | Solaris | GIAGD | REALbasic

Last 30 Days | Last 60 Days | Last 90 Days | All Articles | RSS | Hail Support


Categories:
·GNU/Linux
·Homebrew designs
·Perl
·Administration
·Backup/Recovery
·Bugs/Fixes
·Certification
·Database
·Email
·File/Print
·Hardware
·Information Grab Bag
·Interoperability
·GNU/Linux ABCs
·Monitoring
·Name Resolution
·Network Services
·Networking
·Remote Control
·Security
·Desktop
·Web
·BSD
·Solaris
·GIAGD
·REALbasic
·All Categories


Capturing Selected Text with JavaScript
Topic: Web   Posted:2005-10-27
Printer Friendly: Print

spacerspacer
Here is a way to capture text that is selected within a textarea box. As with this article, I have only included what is necessary for the script to function on a recent browser like IE or Mozilla/Firefox. For an example of how to do this outside a textarea box with even more stringent browser requirements, see this article.

Here is the version for a textarea box:


Select your city from the text above, or type in your own city, and click the place button below.


Here is the source code for the above:

<script language="JavaScript">
function display(txtarea){
var sl = (txtarea.value).substring(txtarea.selectionStart,
txtarea.selectionEnd);  
prompt ("The place you have selected is:",sl);
} 
</script>
<body bgcolor="white"  onload="thisForm=document.frmKey;">
<form method="POST" action="art466.html" id="frmTest" name="frmKey">
<textarea name="entry" rows="10" cols="70">Dallas, got a soft machine. 
Houston, too close to New Orleans.
New York's got the ways and means, but just won't let you be, oh no.</textarea>
<br />
Select your city, and click the place button below.<br />
<img onClick="display(thisForm.entry);" src="images/place.gif">
</form>

For more on the textarea tag, see this reference. For a great doc on this and other JavaScript selection methods, see this. Of particular interest, here, is that you can select any text on the page with later versions of Mozilla and the window.getSelection() function.

For the complete program that uses this, see this article.




Please read our Terms of Use
Microsoft, Windows, Windows XP, Windows 2003, Windows 2000, and NT are either trademarks or registered trademarks of Microsoft Corporation. NetAdminTools.com is not affiliated with Microsoft Corporation. Linux is a registered trademark of Linus Torvalds, and refers to the Linux kernel. The operating system of most distributions that contain the Linux kernel is GNU/Linux. All logos and trademarks in this site are property of their respective owner. Copyright 1997-2008 NetAdminTools.com

Created by:
MCJ
MCJ CMS