Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1728 How can I show the dates for the last two weeks in a select form field?

You are here: irt.org | FAQ | JavaScript | Form | Q1728 [ previous next ]

try:

<html>

<body>

<form>
<script language="JavaScript"><!--
var now = new Date()
var aDay = 24*60*60*1000;
var then = new Date(now.getTime()-(14*aDay));
var text = '<select>';
for (i=then.getTime();i<now.getTime();i+=aDay) {
  var date = new Date(i);
  var year = date.getYear();
  if (year < 1900) year += 1900;
  var dateString = (date.getMonth()+1)+'/'+date.getDate()+'/'+year;
  text += '\n<option value="' + dateString + '">'+ dateString+'</option>';
}
text += '</select>';
document.write(text);
//--></script>
</form>

</body>

</html>

©2018 Martin Webb