Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 417
  • Last Modified:

Create dropdown list displaying 5 previous weekdays(Mon-Fri)

I am looking for a javascript function allowing to display a drop down list with the 5 previous weekdays (if day=Sunday or Saturday, do not display) from today's date under the format mm/dd/yyyy. Would anyone have any starters? Thanks in advance....
0
ontaillou
Asked:
ontaillou
  • 2
1 Solution
 
ZontarCommented:
See if this does what you want.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Weekdays Dropdown...</title>
</head>
<body>
<form>
<script type="text/javascript">
var today = new Date();
var dayNames = ["", "Mon.", "Tue.", "Wed.", "Thu.", "Fri.", ""];
var output = "<select name=\"weekdays\">\n<option value=\"\">[ choose one ]</option>\n";
var day;

for(var i = 0; i < 5; i++)
{
  today.setDate(today.getDate() - 1);

  while(today.getDay() == 0 || today.getDay() == 6)
    today.setDate(today.getDate() - 1);
 
  day = + (today.getMonth() + 1) + "/" + today.getDate() + "/" + today.getFullYear();

  output += "<option value =\"" + day + "\">" + dayNames[today.getDay()] + " " + day + "</option>\n";
}

output += "<select>\n";

document.write(output);
</script>
</form>
</body>
</html>
0
 
ontaillouAuthor Commented:
Thank you Zontar for your help! It is much appreciated! The function worked!
0
 
ZontarCommented:
"All in a day's work for... BICYCLE REPAIRMAN..." <G>

If you need a little more help twiddling that thing to give you just the right output, give me a holler.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now