Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want,when i press enter button in password field it should behave like that i have clicked on login button. how can i associate this.


reply me soon
[Email removed]
Posted
Updated 14-Nov-10 15:15pm
v2
Comments
Henry Minute 14-Nov-10 21:17pm    
You really should not post your Email address in a public forum like The Code Project. You will end up getting loads and loads of spam. It is not necessary either since you get notified of responses to your question.
Xmen Real 15-Nov-10 9:39am    
well, you should have added ASP.Net tag

The form has a property AcceptButton, select your button in it.
 
Share this answer
 
Given below is the javascript code, which will let you do the thing you need.

C#
function KeyDownHandler(e, btn)
 {
    var eventInstance = window.event ? event : e;
    if (window.event) // IE
    {
        if (eventInstance.keyCode == 13) //13 is the key code for enter button
        {
            eventInstance.returnValue = false;
            eventInstance.cancel = true;
            var obj = document.getElementById(btn);
            obj.click();
            return false;
        }
    }
    else if (eventInstance.which) // Netscape/Firefox/Opera
    {
        if (eventInstance.which == 13)
        {
            eventInstance.returnValue = false;
            eventInstance.preventDefault();
            eventInstance.cancelBubble = true;
            var obj = document.getElementById(btn);
            obj.click();
            return false;
        }
    }
}


where e is the name of event, and btn is the id of button whose action you want to be performed(here it is your login button). Be sure to pass the client id of the button. Hope it will be helpful for you.

Anurag
 
Share this answer
 
v3
Comments
ShivKrSingh 26-Nov-10 23:50pm    
thanks for reply me but my application is in vb.net how it will work there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900