Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8012763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:25:47+00:00 2026-06-04T19:25:47+00:00

Possible Duplicate: How may I sort a list alphabetically using jQuery? Technology: Asp.net with

  • 0

Possible Duplicate:
How may I sort a list alphabetically using jQuery?

Technology: Asp.net with jQuery.

Hi geeks,

Overview:
I’m a jQuery noob , I have been working on this Jquery script to enable OnEnter keypress move to the next input element (textarea,select,input ,etc) ,I have tried several solutions of my own ,even tried solutions available online ,but every solution have some weakness or limitation ,well I have finally got a solution which is good enough for me ,but it still has some problems.

Problem:
I have queried all the elements having attribute [tabindex], now jquery returns all the elements in DOM as they are present in their hierarchy ,but I want elements sorted according to their tabindex.

1) So elements needs to be sorted so that I could move to next element based on the tabindex but not on the basis of their hierarchy.
2) What if any element is set to readonly="readonly" or disabled = "disabled" ,that element should not get focus at all ?

I dont want to mess up the question by putting Jquery and HTML code ,so I have created JsFiddle

Let me know how to tackle this.

P.S: Let me know I you guys need more info.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:25:48+00:00Added an answer on June 4, 2026 at 7:25 pm

    NOTE: shamelessly stolen the idea of @Kolink

    $(document).ready(function () {            
         var arr=$(":input[tabindex]:not('[disabled=disabled],[readonly=readonly]')");//this will give you the input elements that are not disabled or readonly
    
         //as Kolink mentioned in his answer use the .sort function of javascript array to sort the array according to the tab index 
         var newArr=arr.sort(function(a,b){   
         return a[1]-b[1];
         });
         console.log(newArr);
         $(newArr[0]).select().focus(); // focus the element with tabindex=1
         var $currentFocus=0;//set the currentFocus pointer to the first element of the sorted array
         var $arrLen = newArr.length;
     $(':input').live("keydown", function (e) {        DO NOT USE .live as it is deprecated but i will go with it for the time being see the link to .delegate at the end of the answer                  
      if (e.which == 13) //Enter key
       {
         e.preventDefault();     
         if($currentFocus<$arrLen){     
            $(newArr[$currentFocus+1]).focus();     
            $currentFocus++;     //increment the pointer    
         }else {
            console.log("submit form");
            alert("submit form");
         }
       }
     }); //end of keydown function
    
    });​
    

    .sort()

    .delegate

    DEMO

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Get Class List for Element with jQuery If I have something like
Possible Duplicate: Pure virtual functions may not have an inline definition. Why? I've come
Possible Duplicate: C++ variable types limits I have a defined type that may not
Possible Duplicate: Jquery event chaining Traditionally we may write: $(selector).click(function () { }); but
Possible Duplicate: load content from external page into another page using ajax/query May be
Possible Duplicate: Classic ASP and ASP.NET Integration I got to work on one application
Possible Duplicate: Search and replace inside an associative array I think this may have
Possible Duplicate: Yield In VB.NET In C#, when writing a function that returns an
Possible Duplicate: Uses for multiple levels of pointer dereferences? I have used functions with
Possible Duplicate: Are there are any platforms where pointers to different types have different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.