Solved

Drop down box in order

Posted on 2013-05-31
3
229 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
3 Comments
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 250 total points
Comment Utility
0
 
LVL 58

Accepted Solution

by:
Gary earned 250 total points
Comment Utility
Your code works fine for me.
http://jsfiddle.net/Sqqbg/1/
0
 

Author Closing Comment

by:tonelm54
Comment Utility
Hmm, dont understand then, must be me :-S

Thanks for your help
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn how to dynamically set the form action using jQuery.
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now