?
Solved

Drop down box in order

Posted on 2013-05-31
3
Medium Priority
?
251 Views
Last Modified: 2013-06-18
Ive got some simple code to populate a select box with the hours of the day:-
        $.each({"00":"00", "01":"01", "02":"02", "03":"03", "04":"04", "05":"05", "06":"06", "07":"07", "08":"08", "09":"09", "10":"10", "11":"11", "12":"12", "13":"13", "14":"14", "15":"15", "16":"16", "17":"17", "18":"18", "19":"19", "20":"20", "21":"21", "22":"22", "23":"23" }, function(key, value) {
            $('.ddHH')
                .append($('<option>', { value : key })
                .text(value));
            });

Open in new window


Which works great however the drop down populates like:-
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09

But I want it to populate as:-
00, 01, 02, 03, 04, 05, 06, 07, 08, 0910, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23

I dont understand where the 'sorting' is coming in, as surely it would just take the first element of the array add it, then the second. I would understand if it was reveresed, but dont understand this :-(

Any ideas?

Thank you
0
Comment
Question by:tonelm54
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 1000 total points
ID: 39210890
0
 
LVL 58

Accepted Solution

by:
Gary earned 1000 total points
ID: 39211078
Your code works fine for me.
http://jsfiddle.net/Sqqbg/1/
0
 

Author Closing Comment

by:tonelm54
ID: 39257095
Hmm, dont understand then, must be me :-S

Thanks for your help
0

Featured Post

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question