Here’s what I have tried, which doesn’t work:
<select name="mois" id="mois">
<option value="" selected="selected">...</option>
<script type="text/javascript">
<!--//
var d=new Date();
var month=new Array(12);
month[0]="Janvier";
month[1]="Février";
month[2]="Mars";
month[3]="Avril";
month[4]="Mai";
month[5]="Juin";
month[6]="Juillet";
month[7]="Aout";
month[8]="Septembre";
month[9]="Octobre";
month[10]="Novembre";
month[11]="Décembre";
document.write('<option value="'+(d.getMonth()+1)+'">'+month[d.getMonth()]+'</option>');
//-->
</script>
</select>
document.writeUse an array literal instead of
new Array(12):Make sure, when checking
d.getMonth, that you loop back to the beginning if the current month is the last month of the year (like it is right now):Once you know the index of next month, you get to choose how to build the new
<option>element and add it to the dropdown:Use the
createElementandappendChildDOM methods.Just use
innerHTMLto do the same thing. A little easier for the developer, butinnerHTMLmight not work on Mobile Safari. Also, if you have event listeners or any other JS stuff going on with the other options in your dropdown, those will be lost.Use
insertAdjacentHTMLto get the ease ofinnerHTML, but without having to discard and rebuild the dropdown’s entire DOM. (However, you’ll need a shim to makeinsertAdjacentHTMLwork with older versions of Firefox.)