1

i'm trying to put simple login form with enter key. The login functionality placed in login button click. I just trying to trigger it on keypress of enter button. But its not working. What is my problem?

  $("#userPassword").bind('keypress', function(e) {
       var code = (e.keyCode ? e.keyCode : e.which);
       console.log("trigger outside "+code);
        if(code == 13) 
        {   
            console.log("trigger insided");
            $( "#loginBtn" ).trigger( "click" );

        }
     });
7
  • have you placed the above code in document.ready function? if not, do that Commented Aug 28, 2014 at 5:55
  • whats the issue you are getting when you click, any error in browser console ? Commented Aug 28, 2014 at 5:55
  • Implying that you are using the newest version of jQuery, I think that "bind" is deprecated and you should be using "on" instead. Commented Aug 28, 2014 at 5:56
  • make button type submit and it should post automatically on pressing enter key Commented Aug 28, 2014 at 5:58
  • @mulla.azzi yes i placed in ready function onlly Commented Aug 28, 2014 at 6:54

2 Answers 2

1

How have you defined or handled the click event on the login button? If this isn't working, then I think you have not bind any function to the click handler and login is working some other way.

From the docs

$( "#foo" ).on( "click", function() {
  alert( $( this ).text() );
});
$( "#foo" ).trigger( "click" );
Sign up to request clarification or add additional context in comments.

1 Comment

It is my login button click function... what is wrong with this? $("#loginBtn").click(function(){ //mycode });
1

If you are trying to make your code run when user presses "Enter" in any of the field in your login form then you are doing it wrong. The proper way is to wrap your login/password fields and submit button into a form and write a form on submit handler.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.