You are here: irt.org | FAQ | DHTML | Q998 [ previous next ]
Only in Netscape Navigator 4+ and Internet Explorer 4+:
<script language="JavaScript1.2"><!-- var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December'); var months = new makeArray('January','February','March','April', 'May','June','July','August','September', 'October','November','December'); function nths(day) { if (day == 1 || day == 21 || day == 31) return 'st'; if (day == 2 || day == 22) return 'nd'; if (day == 3 || day == 23) return 'rd'; return 'th'; } function y2k(number) { return (number < 1000) ? number + 1900 : number; } function monthsahead(noofmonths) { var today = new Date(); var date = new Date(today.getYear(),today.getMonth() + noofmonths,today.getDate(),today.getHours(),today.getMinutes(),today.getSeconds()); return date.getDate() + nths(date.getDate()) + ' ' + months[date.getMonth()] + ' ' + y2k(date.getYear()); } function update(months) { if (document.all) document.all.myDiv.innerHTML = monthsahead(months); else if (document.layers) { document.layers['myLayer'].document.open(); document.layers['myLayer'].document.write(monthsahead(months)); document.layers['myLayer'].document.close(); } } //--></script> <form> <select name="months"> <option value="1">1 Month <option value="6">6 Months <option value="12">1 Year </select> <input type="button" value="Change" onClick="update(this.form.months.options[this.form.months.selectedIndex].value - 0)"> </form> <p> <div id="myDiv"> <layer id="myLayer"> </layer> </div> </p>