Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q998 How can I select a entry from a select form field and display a formatted date on the document not using a text field?

irt.org | Knowledge Base | DHTML | Q998 [ previous next ]

Q998 How can I select a entry from a select form field and display a formatted date on the document not using a text field?

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.