Solved

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

Posted on 2003-11-13
3
391 Views
Last Modified: 2012-05-04
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
Comment
Question by:ontaillou
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Zontar earned 250 total points
ID: 9746039
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
 

Author Comment

by:ontaillou
ID: 9747692
Thank you Zontar for your help! It is much appreciated! The function worked!
0
 
LVL 11

Expert Comment

by:Zontar
ID: 9751271
"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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now