I have a asp.net form content dropdownlist, textbox and button. I want to implement Enter key press to change focus and check input before submit form. I use onkeyup=”EnterPressFocusChange(this, event)” for change focus and OnClientClick=”return CheckInputData(this);” for check input data before submit. When I use button property UseSubmitBehavior=”false” then change focus task working but checking input function always return true and button onCkick function calls. And when I use button property UseSubmitBehavior=”true” then onCkick function calls when I press Enter Key press . How can I complete both task?
<script type="text/javascript">
function CheckInputData(a) {
// If valid input return true
// else return false
}
function EnterPressFocusChange(a, event) {
if (event.which == 13) {
// Change focus
}
}
</script>
<form runat="server">
<asp:DropDownList ID="DropDownList1" runat="server" onkeyup="EnterPressFocusChange(this, event)" AutoPostBack="true"></asp:DropDownList>
<asp:TextBox ID="tb1" Text="0" runat="server" onkeyup="EnterPressFocusChange(this, event)"></asp:TextBox><br />
<asp:Button ID="btnFakeButton" runat="server" Text="Fake Button" OnClientClick="return CheckInputData(this);" UseSubmitBehavior="false" OnClick="btnFakeButton_Click"/>
I want to implement Enter key press to change focus and check input before submit form.