[Javascript] coding for the <enter> key

Peter Brunone peter at brunone.com
Wed Mar 12 21:17:39 CST 2003


Bill,

	As sort of a corollary here... if you're having trouble identifying exactly
what kind of characters are popping out, you can View Source and then paste
the results into the box at

http://aspalliance.com/peterbrunone/analyzethis/analyzethis.asp

for a detailed look at what you've got in your string.

Cheers,

Peter

|-----Original Message-----
|From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
|Subject: Re: [Javascript] coding for the <enter> key
|
|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




More information about the Javascript mailing list