473,809 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Enter Key on Form

I have a form that with a datagrid with textboxes and a submit button. When
the user is in a textbox and they hit enter to try to go to a different
line, instead they submit the form before they are done entering their data.
I know this is how it is supposed to work, but is there anyway to disable
the enter key from hitting the submit button?

Thanks in advance for any advice!

--
Chuck Foster
Programmer Analyst
Eclipsys Corporation - St. Vincent Health System
Nov 19 '05 #1
2 1414
TJS
many have asked this before, look for a javascript solution thru google


"chuckdfost er" <ch**********@h otmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I have a form that with a datagrid with textboxes and a submit button.
When the user is in a textbox and they hit enter to try to go to a
different line, instead they submit the form before they are done entering
their data. I know this is how it is supposed to work, but is there anyway
to disable the enter key from hitting the submit button?

Thanks in advance for any advice!

--
Chuck Foster
Programmer Analyst
Eclipsys Corporation - St. Vincent Health System

Nov 19 '05 #2
"How can I disable enterkey in a form. "
=============== =============== =============== =============== ========

Try using some javascript.
I added it to my Base page that I inherit from and inject it to each child
page.
(As a bonus you get to set the initial focus for any control)

=============== =============== =============== =============== ==========
Add code like this to any child page where you want to set focus to a
control or kill the enter key:

Public Sub New()
MyBase.New()

'set the focus to the UserID text box:
InitialFocus = txtUserId

'Do Not kill the Enter key on this page
Me.killEnterKey = False

'Kill the Enter key on this page
'Me.killEnterKe y = True

End Sub

=============== =============== =============== =============== ==========
Add this code to your javascript library which is loaded for each page:

function NetscapeEventHa ndler_KeyDown(e ) {
if (e.which == 13 && e.target.type != 'textarea' && e.target.type !=
'submit') { return false; }
return true;
}

function MicrosoftEventH andler_KeyDown( ) {
if (event.keyCode == 13 && event.srcElemen t.type != 'textarea' &&
event.srcElemen t.type != 'submit')
return false;
return true;
}

=============== =============== =============== =============== ==========
Add this to the top of your Base page:

Public InitialFocus As Control
Protected KillEnterKey As Boolean = True

=============== =============== =============== =============== ==========
Protected Overridable Sub Page_PreRender( ByVal sender As Object, ByVal e As
EventArgs)

Dim sb As New StringBuilder

'-- Focus
sb.Append("<scr ipt language='javas cript'>")
If Not InitialFocus Is Nothing Then
sb.Append("docu ment.getElement ById('" & InitialFocus.Cl ientID &
"').focus() ;")
End If

'-- Append to the Browser Title set on an instance level

'Code to call the Enter button kill javascript in library
If KillEnterKey = True Then
sb.Append("var nav = window.Event ? true : false;")
sb.Append("if (nav) {")
sb.Append("wind ow.captureEvent s(Event.KEYDOWN );")
sb.Append("wind ow.onkeydown = NetscapeEventHa ndler_KeyDown;" )
sb.Append("} else {")
sb.Append("docu ment.onkeydown = MicrosoftEventH andler_KeyDown; ")
sb.Append("}")
End If

sb.Append("</script>")
RegisterStartup Script("My JScript", sb.ToString())

End Sub

=============== =============== =============== =============== ==========
--
Joe Fallon


"chuckdfost er" <ch**********@h otmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I have a form that with a datagrid with textboxes and a submit button.
When the user is in a textbox and they hit enter to try to go to a
different line, instead they submit the form before they are done entering
their data. I know this is how it is supposed to work, but is there anyway
to disable the enter key from hitting the submit button?

Thanks in advance for any advice!

--
Chuck Foster
Programmer Analyst
Eclipsys Corporation - St. Vincent Health System

Nov 19 '05 #3

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

Similar topics

15
6584
by: M Smith | last post by:
I have a form I want to submit to itself. I want to be able to type in a list of numbers and submit the form and have that list show up on the same form under the text box I typed them into and the buttons. The problem is when I post a form to itself, the Enter key will not submit the form, it only clears the contents of the text box. The only way I can submit is to click the submit button. Here is a simplified version of my code that I...
6
3109
by: CJM | last post by:
Can somebody clarify if/how/when a simple form is submitted when the <Enter> key is pressed? As I understood it, if you have a form with a single submit button, if enter is pressed, the form should be submitted as if the button is pressed. Is this correct? Does this behaviour vary across browsers? Chris
4
7607
by: Peloux | last post by:
Hi, I have written some htc in order to validate data in a form. most of htc are attached on 'onblur' event. Now, we would like to use the Enter Key to sublit form, so we use the following code : ----------- <SCRIPT> function touche_EnterKeyPress(){
7
20378
by: jerrygarciuh | last post by:
Hello, I have been playing with various Googled solutions for capturing the <Enter> key to suppress form submission. My first question is whether anyone has a script that works in all common browsers? The script bellow is IE only. It fails FF 1.0 and NN 7. Also, if I can trap the keypress I would like to use it to tab to the next tabindex.
10
4410
by: Deano | last post by:
I think that just about sums it up. Is there a fix/workaround for this?It's quite annoying behaviour and not user-friendly.thanksMartin
9
7030
by: Megan | last post by:
Hi- I'm creating a database of music bands with their cds and songs. I'm trying to program an SQL statement so that I can enter a string of text in a textbox, press the 'Enter' key, and have it return the associated records to a listbox. Once the listbox has the records, I want to select a record, which will open a form associated with the selected record in the listbox.
1
3524
by: Susan | last post by:
I have a bound form and subform and am trying to enter the data in both forms programatically. The Linkmaster and Linkchild properties are set. My intent is to be able to look at the data before it is saved and then choose to save it or undo it. I have a Save button that just closes the form and a Cancel button that does an undo and then closes the form. I first enter data into the main form and then enter code into the subform. After the...
2
7220
by: Cindy | last post by:
Hi all you smarties out there, I'm having a little conundrum with my asp.net page Scenario: I have a form (asp.net) with no code behind (as yet). I have placed a javascript function on a server side textbox control to do something - eg change the words on label - when the key pressed is the "enter" key. I can see the label change to what i expect ----- BUT .... then the
6
3817
by: guoqi zheng | last post by:
In a regular html form, when user press "enter" key, the form will be submitted. However, in ASP.NET web form, a form will only be submitted (post back) when a special button is clicked. Many user get used to click "enter" key to submit a form. How can I use "enter" key to submit/postback in ASP.NET. Thank, Guoqi Zheng
15
4058
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE CALLING FORM! This is very bad for me, because in my application, Form1 responds to an ENTER keypress by calling Form2. If the user closes Form2 via an ENTER, then Form1 just reopens it again, kind of trapping the user in Form2 (they can still close...
0
9721
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
9601
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
10635
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
10115
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
9198
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...
0
6881
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();...
0
5550
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
4332
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
3861
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.