Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-11-13
3
Medium Priority
?
412 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Zontar earned 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

730 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