Skip to content Skip to sidebar Skip to footer

Identifying Main Submit Button For A Form

I have a form which has a few text boxes, and two submit buttons. When a text box is selected, and I press Enter, the first submit button is triggered. However, this is not the but

Solution 1:

Its pretty tough to get more native than javascript. You're gonna need it here. By the way, the behavior you noticed is the expected behavior. The first submit button in your html is the one that will get sent with your header.

I guess if you really didn't want to use js, you could just put the other button first and then use css to position them correctly on the page itself.

Solution 2:

If you are using asp .net then you can use "UseSubmitBehavior" property on the button. See below code.

<asp:TextBoxrunat="server"ID="txt1"></asp:TextBox><br/><asp:Buttonrunat="server"ID="btn1"UseSubmitBehavior="False"Text="1"OnClick="test1"/><br/><asp:Buttonrunat="server"ID="btn2"UseSubmitBehavior="True"Text="2"OnClick="test2"/>

Post a Comment for "Identifying Main Submit Button For A Form"