[Javascript] coding for the <enter> key
David T. Lovering
dlovering at gazos.com
Wed Mar 12 16:13:23 CST 2003
Assuming that the <enter> key is embedded in the text somewhere in 'var myLine', you could detect it thusly:
if (myLine.search(/\r/g) != -1) {
// hey dude, you've got at least one embedded carriage return!
} else {
// hey dude, no carriage-returns here
}
Similarly, if you wanted to whack all the carriage returns in the line, you could do it like this:
var myLine = myLine.replace(/\r/g, "");
If you wanted to turn them into something visible [like '@' for example], you could do it like this:
var myLine = myLine.replace(/\r/g, "@");
If you want to detect the incoming characters while they're being typed, you'll have to build an event handler
that traps on the keystroke event from the keyboard. [Remember, JavaScript is for the most part on the client
end, so this is possible]. However, IE and Netscape use different keycode events, so you'll have to write a
routine that can handle both platforms.
-- Dave Lovering
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dlovering.vcf
Type: text/x-vcard
Size: 304 bytes
Desc: Card for David T. Lovering
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20030312/e557f352/attachment.vcf>
More information about the Javascript
mailing list