Formatting / Padding Javascript output
Posted: Sun Dec 08, 2002 7:24 am
Hi,
I am designing a form for a competition on my site. It involves guessing lap times for a race. I have three SELECT options, one for guessing the minute, one for the seconds, and one for fractions of a second. I am using JavaScript to write the option values, from 0-59 for the seconds, but I want it to display leading zero's, so 00, 01, ... 09, 10 etc. and three places for the fractions, 000 .. 009 .. 099, 100 etc.
This is what I have. The option value doesn't need padding, but the displayed value does to reduce confusion.
Thanks.
I am designing a form for a competition on my site. It involves guessing lap times for a race. I have three SELECT options, one for guessing the minute, one for the seconds, and one for fractions of a second. I am using JavaScript to write the option values, from 0-59 for the seconds, but I want it to display leading zero's, so 00, 01, ... 09, 10 etc. and three places for the fractions, 000 .. 009 .. 099, 100 etc.
This is what I have. The option value doesn't need padding, but the displayed value does to reduce confusion.
Code: Select all
<select name="s">
<script type="text/javascript">
<!--
for (i = 0 ; i < 60 ; i++)
{
document.write('<option value=' + i + '>' + i + '</option>');
}
//-->
</script>
</select>