473,597 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A simple way to make textarea support submitting the form when pressing Ctrl+Enter

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(e vent.keyCode==1 3 && event.ctrlKey) return
document.form2. submit()'>
</textarea>
</form>

It is not good, because:
1) must give the FORM a name or id.
2) when the "name" of FORM changed, must change the code
3) worst is I must input(or copy) the code.....

I tried a simple way to do this boring thing, and only need input code
once.
1) write a js file, e.g. common.js
/*
* auto support Ctrl+Enter to submit form
* by Net@lilybbs (yuelinniao@hot mail)
*/
window.onload = function()
{
for(var i=0; i < document.forms. length; i++)
{
var frm = document.forms[i];
for(var j=0; j < frm.length; j++)
{
var e = frm.elements[j];
if(!e.type)
continue;
if(e.type=="tex tarea")
e.onkeydown = function(evt)
{
evt=(evt)?evt:( (event)?event:n ull);
if(evt.ctrlKey && evt.keyCode==13 )
{
this.form.submi t();
return false;
}
}
}
}
}

2) when import, the page's textarea(s) support Ctrl+Enter to submit
form
<script type="text/javascript" src="common.js" ></script>

hope help someone. Sorry for my poor English.

Feb 24 '06 #1
3 2963
yu********@gmai l.com wrote:
window.onload
I don't like "window.onload" , I always insert such codes at the end of
the page, just before the </body>, there's a defer property for the
<script> tag, but it doesn't seem to work right =|
e.onkeydown = function(evt)
Since you're offering this to the community, you should assign your
handler using any "addEvent function", to avoid overwriting the user event.
hope help someone. Sorry for my poor English.


That's not my language too :)
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Feb 24 '06 #2
yeah, you are right. 3x for suggestion.
hehe, I only trid to introduce a method here.
so not using prototype.js

Feb 24 '06 #3
yu********@gmai l.com wrote:
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(e vent.keyCode==1 3 && event.ctrlKey) return
document.form2. submit()'>
</textarea>
</form>

It is not good, because:
1) must give the FORM a name or id.
2) when the "name" of FORM changed, must change the code


The created onkeydown function will execute in the context of the input
element. So try "this.form.subm it()" instead of "document.form2 .submit()"
Feb 26 '06 #4

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

Similar topics

1
1530
by: George Homorozeanu | last post by:
Hi, I have an ASP.Net Page with some control on it (buttons, textboxes, calender, etc). When I'm changing the text in the textbox I want to run some code and change the date of the calendar. The problem is that when I press enter, the code for the button event is called. It looks like the button is the default action for pressing enter somewhere on the page. How can I change that? The button is an asp button. Thanks,
10
3026
by: Perry van Kuppeveld | last post by:
Hi, I have a problem with formatting a table including text fields wich can contain up to 255 chars. I need a table with 3 columns: - First column 50 % over the with a rowspan of the total number of rows. - Second column 25 %, no rowspan - Third column 25 %, no rowspan
11
7730
by: Joe | last post by:
Hello All, I have an ASP.NET page with one Textbox (SearchTextBox) and one ImageButton (SearchButton) server controls. The user can type search text in SearchTextBox and click SearchButton and the web server performs a database query and displays the results. All of this works fine. I want the user to be able to press the Enter key while the cursor is still in SearchTextBox and have the SearchButton.Click event fire (thus performing...
2
3560
by: RTT | last post by:
<form id="Form1" method="post" runat="server"> <asp:textbox id="TxtEmail" tabIndex="1" runat="server" Width="272px" ToolTip="Enter your emailaddress for authentication"></asp:textbox> <asp:textbox id="TxtPassword" tabIndex="2" runat="server" Width="272px" ToolTip="Enter your domain password" TextMode="Password"></asp:textbox> <asp:linkbutton id="BtnLogin" tabIndex="3" runat="server">Login</asp:linkbutton> </form> This is the form as i...
1
2153
by: Camellia | last post by:
Hi all, I'll get straight into it. When I try to run the code: ..... while (scanf("%c", &c) == 1) printf("%c", c); ..... I input "abcd" follows by an EOF(Ctrl + d) instead of pressing enter,
1
1955
by: Cub71 | last post by:
How can I avoid a "ding" when enter is pressed in a textbox with multiline == false?
1
1307
by: Gouri.Mahajan7 | last post by:
Hello, I am loading the user control on the web page. In the user control i have added the key down event, when enter key is pressed i am displaying some message. When I run the user control independently it is working fine. But when the user control is loaded on the web page that is not getting fired. What could be problem can anybody explain me.? Actually I have tested the same application before it was working
1
2539
by: sourav08 | last post by:
hi, I'm facing a problem in Mozilla which is ok in Ie. I have few input boxes in my page. After entering some text in one field and pressing the enter key, Onchange event is called for every wrong input and cursor goes back to re-enter the text. In Mozilla when enter key is pressed it first called the onchange event and then simultaneously calling the onsubmit function written in Javascript. In IE it is not throwing the onsubmit event...
0
8272
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
8381
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...
1
8035
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8258
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...
0
6688
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5847
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
5431
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2404
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
0
1238
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.