Focus on next textbox by enter press RRS feed

  • Question

  • User855106052 posted

    I have 3 textboxs and a button. I have the focus on the first.

    How do I press the enter key to jump the focus to the second textbox and when that focus is in the second press enter and jump the focus to the third and at the end pressing the enter key jump the focus to the button and enter key execute button onclick?

                    <asp:Textbox ID="TbxDesc" runat="server"></asp:Textbox>
                    <asp:Textbox ID="TbxQuant" runat="server"></asp:Textbox>
                    <asp:Textbox ID="TbxValue" runat="server"></asp:Textbox>
                    <asp:LinkButton runat="server" ID="BtnSave" OnClick="Save">
                        <i class="fa fa-floppy-o" aria-hidden="true" style="margin-right:11px;"></i>&nbsp;save
    	Sub Page_Load()
                    If Not Page.IsPostBack Then
    		End If
    	End Sub

    Thanks for your help :)

    Saturday, November 28, 2020 4:10 PM


  • User1535942433 posted

    Hi indesk,

    Accroding to your description,do you must use code behind to implement these operations?

    I suggest it's best way that  you could javascript to tab textboxes and execute the button click event.

    Just like this:

     <script src="Scripts/jquery-1.10.2.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var inputs = $(':input').keypress(function (e) {
                    if (e.which == 13) {
                        var next = $(this).next();
                        if (next.prop = "input") {
                        else {
                            __doPostBack('<%=BtnSave.UniqueID%>', "");
    <asp:TextBox ID="TbxDesc" runat="server"></asp:TextBox>
                <asp:TextBox ID="TbxQuant" runat="server"></asp:TextBox>
                <asp:TextBox ID="TbxValue" runat="server"></asp:TextBox>
                <asp:LinkButton runat="server" ID="BtnSave" OnClick="BtnSave_Click">
                        <i class="fa fa-floppy-o" aria-hidden="true" style="margin-right:11px;"></i>&nbsp;save
                <asp:Label runat="server" ID="lb1" Text=""></asp:Label>


     Protected Sub BtnSave_Click(sender As Object, e As EventArgs)
            lb1.Text = "1"
        End Sub

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 30, 2020 2:37 AM