1

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); 
RussellHarrower
  • 6,470
  • 21
  • 102
  • 204
  • Duplicate of http://stackoverflow.com/questions/1267283/how-can-i-create-a-zerofilled-value-using-javascript and also kneejerk reaction: you should *never* prepend numeric literals in JavaScript with 0, since they are actually octal literals (0123 is actually 83, **not** 123). –  Aug 30 '11 at 02:09

1 Answers1

2

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.

  • Your comment was very vague. You should update your question to reflect the additional code I suggested if you didn't get it to work. Or if you did get it to work, you should accept the answer. Thanks. –  Aug 31 '11 at 00:37