RussellHarrower
RussellHarrower

Reputation: 6820

jquery - single digit numbers should start with 0

Hi I am wondering is there anyway to make a single digit number ie:1 become 01

This is the code I using at the moment but all the single digits are only coming out as single digits

 setTimeout(function() {
                            if(a == "hh")
                            {
                                var minOffset = 01, maxOffset = 12;
                            }
                            else
                            {
                                var minOffset = 01, maxOffset = 60;
                            }

                            var timeSelector = $('select[name='+a+']');
                            var thisYear = new Date().getFullYear();
                            //var select = $('<select name="year" id="yyyy" class="formbox dobselect">');

                            for (var i = minOffset; i <= maxOffset; i++) {
                                var time = i;
                                $('<option></option>')
                                .attr('label', time)
                                .attr('value', time)
                                .html(time)
                                .appendTo(timeSelector);
                            }


                        },900); 

Upvotes: 1

Views: 2153

Answers (1)

user336063
user336063

Reputation:

Here's an example that demonstrates what I think you're after:

var tstr = "";
if(time <10)
{
    tstr = "0";
}
tstr += time;

Then put tstr wherever you want to display it.

Upvotes: 2

Related Questions