Reputation: 5670
I have two buttons in my page.First one
<input id="btnSearch" type="button" onclick="searchClick();" value="" tabindex="2">
Second one
<input name="btnSignUp" id="btnSignUp" class="button03" type="submit" value="Bekræft">
As you can see both buttons are of type submit
. When I press enter key always second one get clicked.I want to change it, I want the first button to be clicked always.
Is there any way to achieve this, with out changing the attribute type of both buttons.
Upvotes: 1
Views: 3771
Reputation: 914
Try this, but first make sure to use different ids for the buttons...You can only use one id once.
$(document).ready(function(){
$('#formID').keypress(function(e){
if(e.keyCode==13)
$('#btnSignUp').click();
});
});
Upvotes: 4