On Enter

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

On Enter

Post by hawleyjr »

I'm creating a chat application. If the user hits the "Enter" key while in the message textarea I want to submit the form. However, if the user hits "SHIFT-ENTER" I want it to do a soft return and not submit the form.

I know there is a key capture function I'm just not sure how to do the SHIFT-ENTER part.

Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

viewtopic.php?t=37059

may be of interest.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Hehehe.... check my code snippet in here for write_r(). Ermm... actually don't that's just how I discovered this ;)

Here's how to do it:

1. Capture all keypress events
2. Check if keycode == <whatever> the enter keycode is
3. Look if "shiftKey" is set (i.e shift key was held down at the same time)

This info comes out in the window.Event object :D
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

feyd wrote:viewtopic.php?t=37059

may be of interest.
Feyd that code you posted is awesome.

THX
Post Reply