Solved

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

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

Technology Partners: 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

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

738 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