473,382 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 1367
TJS
many have asked this before, look for a javascript solution thru google


"chuckdfoster" <ch**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.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.killEnterKey = True

End Sub

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

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

function MicrosoftEventHandler_KeyDown() {
if (event.keyCode == 13 && event.srcElement.type != 'textarea' &&
event.srcElement.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("<script language='javascript'>")
If Not InitialFocus Is Nothing Then
sb.Append("document.getElementById('" & InitialFocus.ClientID &
"').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("window.captureEvents(Event.KEYDOWN);")
sb.Append("window.onkeydown = NetscapeEventHandler_KeyDown;")
sb.Append("} else {")
sb.Append("document.onkeydown = MicrosoftEventHandler_KeyDown;")
sb.Append("}")
End If

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

End Sub

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


"chuckdfoster" <ch**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.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
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...
6
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...
4
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...
7
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...
10
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
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...
1
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...
2
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...
6
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...
15
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.