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

Simulate button click on Return key press

Dan
Consider a simple form with a textbox and button.

Is there a way to handle the common situation where a user presses "return"
rather than clicks on the button.

I can already detect the "return" key press using the textbox's onkeypress
event and now what I'm looking for is something like:

onkeypress="if 'return' key pressed, then button.click=True"

Any ideas?

Nov 18 '05 #1
3 7791
Dan
Maybe I should try searching for Enter key first....

You can intercept the client side enter keypress event of the text box and
then click do what you want using javascript code.
Here's a good example:
http://www.kamp-hansen.dk/pages/show...d=21&menuid=18

Or you might try using this free control.
http://www.metabuilders.com/tools/DefaultButtons.aspx

And here's a good article on the subject:
http://www.allasp.net/enterkey.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"Abhram Jose" <ab*****@yahoo.com> wrote in message
news:Ox**************@TK2MSFTNGP11.phx.gbl...
I have written an ASP.Net application.
It has several edit box to enter data. How to program in such way that when the user hits enter key focus will go to next edit box (required control )
and so on ?
Thanks for your suggestions.
Abhram Jose


"Dan" <da*@dontspam.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... Consider a simple form with a textbox and button.

Is there a way to handle the common situation where a user presses "return" rather than clicks on the button.

I can already detect the "return" key press using the textbox's onkeypress
event and now what I'm looking for is something like:

onkeypress="if 'return' key pressed, then button.click=True"

Any ideas?


Nov 18 '05 #2
onkeypress="if(event.keyCode==13) document.getElementById('someButton').click()

or in other words just call the buttons click() method.

but I have no idea how to get the buttons id as the .NET framework changes all ids do something like _ctl1$_ctl4$someButton... naturally you can viewsource your page and see what id it generates and use that but that kinda hardcodes and if you change your control tree layout it might stop working.
im sure there's a way to get around this though...
Nov 18 '05 #3
Dan
Thanks for this.

"Adrijan Josic" <an*******@discussions.microsoft.com> wrote in message
news:71**********************************@microsof t.com...
onkeypress="if(event.keyCode==13) document.getElementById('someButton').click()"
or in other words just call the buttons click() method..

but I have no idea how to get the buttons id as the .NET framework changes all ids do something like _ctl1$_ctl4$someButton... naturally you can
viewsource your page and see what id it generates and use that but that
kinda hardcodes and if you change your control tree layout it might stop
working.. im sure there's a way to get around this though...

Nov 18 '05 #4

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

Similar topics

4
by: johnny | last post by:
On a form I would like to simulate a button click when the Enter is pressed. My form is setup and it works if the delegate for the key pressed on the form calls the delegate for the button pressed....
5
by: Girish | last post by:
I have TWO submit buttons of type IMAGE on my asp form. This renders as <input type="image">. I need to be able to eble the ENTER button for both buttons. Yes, I know that for the input type...
3
by: graphicsxp | last post by:
Hi, I've written some javascript function so that if a textbox has the focus and the user press enter, it triggers a click on a button 'associated' to this textbox (see code at the end) The...
3
by: John Dalberg | last post by:
I have an app that keeps popping up a windows with a 'Yes' or 'OK' button on it. I am trying to write a little app that automates hitting the enter key so I don't have to do it myself. I used...
18
by: eliss.carmine | last post by:
Is it possible to simulate a mouse click in the window I made (it's a Form), but not give it focus? I tried using WinAPI's mouseevent and SendMessage of WM_LBUTTONDOWN/WM_LBUTTONUP as suggested...
3
by: =?Utf-8?B?SmFrb2IgTGl0aG5lcg==?= | last post by:
I have two sets of search criteria on my page. They are placed inside two DIV tags made visible/hidden by a client script. In each DIV tag I have a LinkButton that performs the search from each...
2
by: Max2006 | last post by:
Hi, I have a simple form with a button on it. After a button click postback, anytime user press F5 (browser page refresh), the button's OnClick event handler is called again without the button...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...
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
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,...
0
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...
0
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...

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.