473,473 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

invoking onclick when pressing the Enter key, in a textarea

I'm researching the Enter key. This is for an Ajax chat application.
The designer tells me that she wants people to be able to submit text
simply by hitting the Enter key. She wants this to happen even if
people still have the cursor inside the textarea where they have just
been typing.

I started researching this and came upon this post by Michael Winter,
from 2004:

http://groups.google.com/group/comp....9e99418caa29f4

"If the button has focus, pressing enter will invoke an onclick event.
If some other control (in a form) has focus, the form's submit button
will receive the event. As I see it, if you do want to invoke an event
on an arbitrary control, you'll have to handle the onkeydown event on
*every* control that might be active when Enter is pressed and fire
the event yourself. That's a lot of work."
Huh. Well, before I run off and do a bunch of work, let me clarify
this. If I just want the one textarea to trigger an event when the
Enter key is hit, I only need to override the event handling for that
one textarea, yes?

How does one capture this? Do I examine onkeydown to see if the Enter
key is the key being pushed down?

Sep 20 '07 #1
3 3270
Jake Barnes wrote:
If I just want the one textarea to trigger an event when the
Enter key is hit, I only need to override the event handling
for that one textarea, yes?
Not to override (you can't), but to add to it.
How does one capture this? Do I examine onkeydown to see if
the Enter key is the key being pushed down?
Good idea.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Sep 20 '07 #2
Jake Barnes wrote:
I'm researching the Enter key. This is for an Ajax chat application.
The designer tells me that she wants people to be able to submit text
simply by hitting the Enter key.
If the text entry field is the only input field in the form, then
pressing enter will submit the form anyway, without any need for
JavaScript.

If there are multiple input fields then the result is browser dependant.
If, like me, your application is targetted at a know audience, with a
known selection of browsers, then this might not matter, but I wouldn't
rely on this mechanism, as I like to support users who use "unsupported"
browsers.

--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
Sep 21 '07 #3
Steve Swift wrote:
Jake Barnes wrote:
>I'm researching the Enter key. This is for an Ajax chat application.
The designer tells me that she wants people to be able to submit text
simply by hitting the Enter key.

If the text entry field is the only input field in the form, then
pressing enter will submit the form anyway, without any need for
JavaScript.
In this case, no. That behavior applies to input[type="text"], not to
textarea which is explicitly designed for multi-line input. Hence him
asking whether to handle the `keydown' event (which you did not quote),
and my replying yes.

On a side note, handling the proprietary `keypress' event would be better
in terms of behavior because canceling that event prevents input of a
newline in the textarea also in Geckos, in contrast to `keydown'. However,
it would not be better in terms of compatibility, and probably the users
won't notice the newline anyway.
PointedEars
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Sep 21 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sarah | last post by:
Hi... I have a problem and I hope someone can help me out! I have two series of radio buttons...(call them Group A and Group B) and a Textarea. When you click on any of the radio buttons in...
11
by: Shaiboy_UK | last post by:
Hi All, Hope someone can help here!! I'm putting a standard mail page together, that will allow my users to sent templete emails out to people. The files are stored in text files. I have...
5
by: Mike | last post by:
In my previous post, I wrote: > ... > GOAL: (very simple) Provide a hyperlink which, when clicked, > calls a javascript function which opens a new URL. > ... > PROBLEM: The following code...
3
by: yuelinniao | last post by:
hi, I have got a simple way to make "textarea" support "auto-submit" when pressing Ctrl+Enter, and tested under both IE and Firefox. The common old method is like this: <form name=form2>...
3
by: juicy | last post by:
Hi, I have 4 check box and a textarea. When user check each check box, it will append text in the textarea. In onclick event, it calls getSurcharge function and append value in variable output....
11
by: Daz | last post by:
Hello everyone. I am sure the answer to my question is simple, but I can't seem to dynamically add an onClick event to my script. I have a table which is generated dynamically, I am just...
1
by: Big George | last post by:
Hello, Controls on webpage: - Datagrid - TextBox Datagrid has Delete button: <asp:TemplateColumn HeaderText="Borrar"> <HeaderStyle Width="10%"></HeaderStyle>
10
by: art | last post by:
Hi, I have a form with an image button like this: <td><input type='text' name='search' id='search' value='' size=30><BR><span class=body><center>Enter Email Address</span><BR></ td> <td><a...
3
by: Dreea | last post by:
Hello I have designed a control that consists of a textarea and a button. When the user writes text in the textarea and the Enter key is pressed then the onClick event of the button is triggered....
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.