Forum Moderators: open

Message Too Old, No Replies

how to make submit button select automatically?

How do i make a submit button select automatically after user enters data

         

x187lockdown

11:04 pm on Feb 10, 2005 (gmt 0)

10+ Year Member



Hi all,

Having an annoying problem on my site, it is built using asp.net and c# and has a user login box in the corner of the homepage and a search facility. The problem is that when the user enters there username followed by password and then presses enter, the submit button is not pressed and the page refreshes instead and clears the username and password just entered. The submit button works because if you press it with the mouse instead of pressing enter it logs the user in. The same problem happens with the search.

What I want to know is how to submit the form (username/password, search) when the user presses enter? instead of refreshing the page! Any help appreciated

Jimmy Turnip

12:23 pm on Feb 11, 2005 (gmt 0)

10+ Year Member



Try adding attributes to the button in the code behind that are called on an enter press:


SubmitButton.Attributes.Add("onkeypress", "if(event.keyCode==13){return true;}")

or try:


SubmitButton.Attributes.Add("onkeypress", "if(event.keyCode==13){document.Form1.submit();}")

x187lockdown

7:45 pm on Feb 11, 2005 (gmt 0)

10+ Year Member



Thanks Jimmy. Very much appreciated.

x187lockdown

confused

11:51 pm on Feb 12, 2005 (gmt 0)

10+ Year Member



Would you happen to know how to do this in VB.net?

mattglet

2:47 am on Feb 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That *should* work in VB.NET as well. All you are doing is adding some javascript.

carguy84

5:01 am on Feb 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



is the login form embedded in the search form or something?