473,800 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
+ 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 3310
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 bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.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 "unsupporte d"
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
3354
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 the A group, it automatically adds some text to the textarea, using a javascript onClick function. When you click on any of the radio buttons in the B group, it appends
11
5656
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 come up with a script to produce the names into a Select list, but know i'm wanting them to be read into a textarea box, to allow me to submit them into from the form into the sendmail.asp page! but the only way i can pass them out, is into a...
5
10886
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 works fine if I click to open in > the same window, but if I click the browser option to open in a > new window, the new window tries to open the href URL (the > onClick function does get executed, but seems to be ignored). > ...
3
2985
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> <textarea onkeydown='if(event.keyCode==13 && event.ctrlKey) return document.form2.submit()'> </textarea> </form>
3
3041
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. My problem is I failed to get value in php variable inside the function. Please give some idea on the reason of the problem. Thanks. <script language="JavaScript"> function getSurcharge(id)
11
11216
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 struggling getting an onClick event to show in the HTML source. Any help would be appreciated. Here is a block of my current code which doesn't work. var tr1 = document.createElement('tr');
1
5410
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
4181
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 href='#'><img src='./images/search.gif' border=0 onclick='return getCustomer(search.email.value);'></a><BR><BR></td>
3
3386
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. Is there any way I can make the Enter key not trigger the onClick event of the button. Or in the buttonclicked event handler to determine if the button was clicked or the enter was pressed? Any help would be very appreciated Thanks in advance
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10504
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10274
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10033
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7576
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4149
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 we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.