473,394 Members | 2,100 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,394 software developers and data experts.

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 1405
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*********@stagparkway.com> wrote in message
news:%2****************@TK2MSFTNGP09.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
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...
6
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...
3
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...
5
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...
13
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...
0
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...
0
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...
1
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...
1
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...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...

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.