user2210567
user2210567

Reputation: 11

Submit Form on Enter Key press for two different div tags

I have a Form with login Controls with two div tags

First DIV with UserName, Password and Login button and also I have Forgot Password Link in the Form..When we click on it it shows another div with enter Email id textbox and submit button.

I used Jquery for Enter Key press to submit the form it worked fine.. but in case of forgot password link click it shows another div.. with Submit button but the enter key not working for that div on key press

Here is my jQuery code:

$('#form input').keydown(function (e) {
       if (e.keyCode == 13) {
           $('#form1').submit();
       }
   });

How submit form on enter key press for both div buttons(Login and Submit). Kindly help with required Jquery

Upvotes: 1

Views: 2654

Answers (1)

James
James

Reputation: 53

You can add multiple elements to a keydown or any other function simply by separating them with a comma.

$('#form #UserName, #form #password').keydown(function (e) {
    if (e.keyCode == 13) {
        $('#form1').submit();
    }
});

Upvotes: 5

Related Questions