Solved

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

Posted on 2003-11-13
3
394 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

919 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

16 Experts available now in Live!

Get 1:1 Help Now