1

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.

None
  • 5,582
  • 21
  • 85
  • 170
  • Take a look here: http://stackoverflow.com/questions/48/multiple-submit-buttons-in-an-html-form – Irvin Dominin Dec 02 '13 at 13:05
  • you can use a `Panel` and set a property `DefaultButton` I believe to achieve this. [link](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.panel.defaultbutton(v=vs.110).aspx) – Squirrel5853 Dec 02 '13 at 13:06
  • try to set z-index, may be it will help – Amit Dec 02 '13 at 13:07
  • Please look at http://stackoverflow.com/questions/1041247/handle-user-hitting-enter-key-in-a-asp-net-mvc-web-site – Sarvesh Dec 02 '13 at 13:07

1 Answers1

4

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();
        });
    });
Acelasi Eu
  • 914
  • 2
  • 9
  • 30