0

The problem is , when i hit enter key , it refreshes the page and put me into the same page , it doesnt even execute the alerts I am using this javascript code to login by hitting enter key but it doesn't work .

 $("#btnLogin").keypress(function (e) {
        var code = e.which; 
        alert("stage 1");
        if (code == 13) {
            e.preventDefault();

                alert("stage 2");

        }

    });

i have used keyup,keydown also but they give me the same result, this is my html button

 <button class="btn btn-success" type="button" id="btnLogin">
                        Sign In</button>

Any help appreciated .

L A
  • 966
  • 11
  • 25
akaminko
  • 71
  • 1
  • 2
  • 11

2 Answers2

0

Inside of your if statement you need to add e.preventDefault() in order for it not to submit your form (which is what the default for enter key in a form).

Tuvia
  • 859
  • 4
  • 15
0

The issue is resolved

i have used following code

 $(document).keypress(function (e) {
        if (e.which == 13) {
           alert('You pressed enter!');

        }
    });

instead of using LoginId in used document and then it worked .

I found the answer from the link below here it is

Thanks for your time you spend toanswer the question above

Community
  • 1
  • 1
akaminko
  • 71
  • 1
  • 2
  • 11