Does anyone know how can I default/focus a button by using jquery?
If I have a page with 3 input box and 3 button for difference action. How could I default the button when the user enter value into the input box.
Example:
Based in the following code, let say when the use key in the value under age input, then pressed enter instead of clicked on the search button (ID=”btnAgeSearch”) to do the search. How could I default/focus the button to (ID=”btnAgeSearch”), so that the system will call btnAgeSearch_Click function to do the search instead button (ID=”btnNameSearch”) or button (ID=”btnColorSearch”).
<table border="0" width="900px">
<tr>
<td>Name: </td>
<td colspan="2">
<asp:TextBox ID="sName" runat="server" Width="150px" />
<asp:Button ID="btnNameSearch" runat="server" Text="Search" CausesValidation="false" OnClick="btnNameSearch_Click"/>
</td>
</tr>
<tr>
<td>Or<br />Age: </td>
<td colspan="2">
<asp:TextBox ID="sAge" runat="server" Width="150px" />
<asp:Button ID="btnAgeSearch" runat="server" Text="Search" CausesValidation="false" OnClick="btnAgeSearch_Click"/>
</td>
</tr>
<tr>
<td>Or<br />Color: </td>
<td colspan="2">
<asp:TextBox ID="sColor" runat="server" Width="150px" />
<asp:Button ID="btnColorSearch" runat="server" Text="Search" CausesValidation="false" OnClick="btnColorSearch_Click"/>
</td>
</tr>
</table>
Then on add an keydown event onkeydown=”return buttonClicked(event);”.