473,569 Members | 2,845 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with Enter key and disabling button click

I have a javascript function that is fired on the KeyDown event of a
textbox. I am adding the attribute to the textbox at page load to run this
javascript function. The javascript runs as expected and the text box that
is specified in the javascript gets the focus set to it, but my problem is
that the default button on the form is being pressed also so once the
textbox gets the focus, you barely see it before the page redirects. I want
this javascript to run and to somehow cancel out the button click event.
Anyone know how?

Thanks in advance!

function GetEnter() {
if (event.keyCode == 13) // If key that was pressed is Enter key
document.Form1. txtPartNumber2. focus(); //Set focus to txtPartNumber2
}
Nov 18 '05 #1
1 1415
Hi,

what if after setting the focus to the textbox you'd call 'return;' or
'return false;' (I don't now remember did they behave differently, but try
both of them). It should prevent the butting being activated & pressed.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"David Hearn" <da*********@st agparkway.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
I have a javascript function that is fired on the KeyDown event of a
textbox. I am adding the attribute to the textbox at page load to run this
javascript function. The javascript runs as expected and the text box that
is specified in the javascript gets the focus set to it, but my problem is
that the default button on the form is being pressed also so once the
textbox gets the focus, you barely see it before the page redirects. I want this javascript to run and to somehow cancel out the button click event.
Anyone know how?

Thanks in advance!

function GetEnter() {
if (event.keyCode == 13) // If key that was pressed is Enter key
document.Form1. txtPartNumber2. focus(); //Set focus to txtPartNumber2
}

Nov 18 '05 #2

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

Similar topics

1
1280
by: Denzen Stupilla | last post by:
hi all, I have a asp.net webform with textboxes and buttons. What's the trick to disabling the button on-click events to fire when Enter key is pushed? i want the server click events for the buttons to fire ONLY when the button is clicked with the mouse. thanks so much. Denzen
6
391
by: Mark Reed | last post by:
Hi all, I am trying to learn a little about programming (I know next to nothing so far) and have found some code which hides the toolbars. However, this bit of code is a little too effective and hides all of them including hiding the database window, disabling menu changes. What I am after is the same effect as disabling all the check boxes...
3
7638
by: DC | last post by:
I need help. I've confused myself with all of the things I've tried. I'm trying to modify the exiting Contacts template in Access 2000 to include a search option. To the Contact Entry form I've added an unbound text field with lable and a command button. The following code is in the On Click event of the Command button. Private Sub...
5
6806
by: Steve | last post by:
Hi, Is it possible to make hitting the enter key in an ASP textbox run the code behind an ASP button on a form? I have a search page which users tend to type in the query then just hit enter rather than actually clicking the search button, but this does not run the search code behind the button.
13
4311
by: Joner | last post by:
Hello, I'm having trouble with a little programme of mine where I connect to an access database. It seems to connect fine, and disconnect fine, but then after it won't reconnect, I get the error "operation is not allowed when object is open" so I take out the line of code: BookDetails.Connection1.Open and it comes up with the error...
0
973
by: VBLearner | last post by:
Hi I am taking intermediate level VB.Net class. Currently, we are doing the second review project which is quite big. It is a voting system where we display the participants for Candiadets and measures by reading from a flat file and after the user finsihes voting, we allow the user to cast the vote by clicking a button which will display a...
0
5542
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
1
1355
by: =?Utf-8?B?SlA=?= | last post by:
Using C# and JavaScript Framework 2.0 My users want to be able to start a search by clicking the enter key. Since the page uses View control, I placed an onkeypress event on the table for each view to check for keyCode 13. If it detects the enter key, then it calls a JS function that does some validation and then calls the button click that...
1
6983
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the page has multiple button such login page with a search function somewhere around, then it's not respond properly. I have attached a brief example of...
0
7922
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. ...
0
8119
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...
1
7668
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...
0
7964
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...
0
6281
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...
1
5509
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...
0
3653
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...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
936
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...

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.