|
Q750 How can I pass the current date to a select form fieldmMenu and have it selected when the page is loaded?
irt.org | Knowledge Base | JavaScript | Form 3.3 | Q750 [ previous next ]
Q750 How can I pass the current date to a select form fieldmMenu and have it selected when the page is loaded?
Try:
<SCRIPT LANGUAGE="JavaScript"><!--
function padout(number) { return (number < 10) ? '0' + number : number; }
var today = new Date()
var ftoday = padout(today.getDate()) + '/' + padout((today.getMonth() + 1)) + '/' + today.getYear()
var output = '<FORM><SELECT>';
for (var i=-7; i<7; i++) {
aday = new Date(today.getYear(),today.getMonth(),today.getDate() + i)
faday = padout(aday.getDate()) + '/' + padout((aday.getMonth() + 1)) + '/' + aday.getYear()
output += '<OPTION ';
if (faday==ftoday)
output += ' SELECTED';
output += '>' + faday;
}
output += '<\/SELECT><\/FORM>';
document.write(output);
//--></SCRIPT>
|
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.