Click to See Complete Forum and Search --> : months as non-integers


drew69
03-30-2003, 11:42 PM
I am very new to this and appologize if this is a dumb-ass question!
I am writing a drop down box that will have the 12 months listed, I have written it so that whatever month is next will appear first. However, the months appear as integers.

Is there a way to get JavaScript to write these months in characters without writing a ton of code for every choice in the drop down box?

Any help will be appreciated!

gil davis
03-31-2003, 05:43 AM
Originally posted by drew69
Is there a way to get JavaScript to write these months in characters without writing a ton of code for every choice in the drop down box? It would be helpful if we had a sample of what you have now.

Perhaps something like this?<head>
<script>
var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var now = new Date();
</script>
</head>
<body>
<form onsubmit="return false">
<select name="month">
<script>
var mo = now.getMonth();
for (var i=0; i<=11; i++)
{theMonth = months[(mo + i) % 12];
document.writeln('<option value="' + theMonth + '">' + theMonth);}
</script>
</select>
</form>
</body>