views:

322

answers:

3

I've built a login page that uses a .ajax call to a generic c# handler (.ashx) to validate the username and password before allowing the user to log in.

If you click on the login link

<a href="#" class="ui-state-default ui-corner-all CustomButton" onclick="goLogin();return false">

the .ajax call returns successfully and it logs the user in. I am trying to make it so the user can also just press the "enter" key from the password box:

$("#pword").keydown(function(e) {
    if (e.keyCode == 13) {
        goLogin();
    }
});

Using Firefox, both ways work just fine and the user is logged in. With Chrome however, pressing "enter" hits the error function of my .ajax call and will not log the user in.

The parameters and responses look identical through Firefox's console, as expected. What would be causing this and/or how can I debug it in Chrome?

A: 

You can just make jQuery click the link as well:

$("#pword").keydown(function(e) {
    if (e.keyCode == 13)
      $(".CustomButton[href=#]").click(); 
      //Really should give <a> an ID, e.g. $("#LoginBtn").click();
});

Whatever the button does, enter will now do as well...this tends to route around some browser issues like you're seeing as well.

Nick Craver
I gave the button an ID as suggested and call the click. That didn't seem to make a difference, still works both ways in firefox but only by clicking the button in chrome
wham12
A: 

Hey Skiffman...

I had th same issue. Using keypress and returning false fixed the issue in Chrome and Safari.

$("#pword").keypress(function(e) {
    if (e.keyCode == 13) {
        goLogin();
        return false;
    }
});

Hope this helps.. BuR

burlistic
A: 

The issue was actually caused by an error in my html. I accidentally had nested forms and Chrome does not render the first nested form (but it does render all subsequent nested forms, so the rest of the page looked and worked fine).

wham12