Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Saturdays

Reply
Thread Tools

Saturdays

 
 
Maarten
Guest
Posts: n/a
 
      01-19-2004
Hi,

i need to fill a dropdownlist in a frame with only saturdays.

The code must be like:

<select class="fld" size="1" name="arrivaldate">
<option value="17/01/2004">17/01/2004</option>
<option value="24/01/2004">17/01/2004</option>
<option value="31/01/2004">17/01/2004</option>
</select>

and so on....

Can somebody show how to do this with JS?
Thx
Maarten.


 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      01-19-2004
Maarten said:
>
>Hi,
>
>i need to fill a dropdownlist in a frame with only saturdays.
>
>The code must be like:
>
><select class="fld" size="1" name="arrivaldate">
><option value="17/01/2004">17/01/2004</option>
><option value="24/01/2004">17/01/2004</option>
><option value="31/01/2004">17/01/2004</option>
></select>
>
>and so on....
>
>Can somebody show how to do this with JS?


<html>
<head>
<script type="text/javascript">
// function zp zero pads a number to 2 digits.
function zp(n){return (n<10)?"0"+n:n}
var saturdays=new Array();
var now=new Date();
var nextYear=new Date(now.getFullYear()+1,0,1);
// nextYear is the first day of next year
var saturday=new Date(now.setDate(now.getDate()+6-now.getDay()));
// saturday is now the first Saturday after yesterday.
while(saturday<nextYear){
var DDMMYYYY=zp(saturday.getDate())+"/"+
zp(saturday.getMonth()+1)+"/"+
saturday.getFullYear();
saturdays[saturdays.length]="<option value=\""+
DDMMYYYY+"\">"+
DDMMYYYY+"</option>";
saturday.setDate(saturday.getDate()+7);
}
</script>
</head>
<body>
<form>
<select>
<script type="text/javascript">
document.write(saturdays.join(""));
</script>
</select>
</form>
</body>
</html>

 
Reply With Quote
 
 
 
 
Brian Genisio
Guest
Posts: n/a
 
      01-19-2004
Maarten wrote:

> Hi,
>
> i need to fill a dropdownlist in a frame with only saturdays.
>
> The code must be like:
>
> <select class="fld" size="1" name="arrivaldate">
> <option value="17/01/2004">17/01/2004</option>
> <option value="24/01/2004">17/01/2004</option>
> <option value="31/01/2004">17/01/2004</option>
> </select>
>
> and so on....
>
> Can somebody show how to do this with JS?
> Thx
> Maarten.
>
>


Here is a quick way to do it... I am sure there are others...

var msInDay = 1000 * 60 * 60 * 24;

// Get today's date
var today = new Date();

// Set the date to saturday 0 = Sunday to 6 = Saturday
var dayOffset = (6 - today.getDay()) * msInDay;

var saturday = new Date();

// output the next 12 saturdays
for(i=0; i<12; i++)
{
saturday.setTime( today.getTime() + dayOffset + (7 * i * msInDay) );
document.write(saturday.toDateString() + "<BR>");
}

 
Reply With Quote
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      01-19-2004
Brian Genisio <(E-Mail Removed)> writes:

> Here is a quick way to do it... I am sure there are others...
>
> var msInDay = 1000 * 60 * 60 * 24;


Bad idea. The date object has much safer ways to add one day, that
won't get confuzed by changes to and from daylight saving time.

> // Get today's date
> var today = new Date();
>
> // Set the date to saturday 0 = Sunday to 6 = Saturday
> var dayOffset = (6 - today.getDay()) * msInDay;


Just use
var dayOffset = 6 - today.getDay();
and use it on the date, not the milliseconds.

Shorter version:

var date = new Date();
date.setDate(date.getDate()+6-date.getDay()); // first coming Saturday.
for(var i=0;i<10;i++) {
document.write(date.toString() + "<br>");
date.setDate(date.getDate()+7);
}

/L
--
Lasse Reichstein Nielsen - http://www.velocityreviews.com/forums/(E-Mail Removed)
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
Janwillem Borleffs
Guest
Posts: n/a
 
      01-19-2004
Maarten wrote:
> i need to fill a dropdownlist in a frame with only saturdays.
>
> The code must be like:
>
> <select class="fld" size="1" name="arrivaldate">
> <option value="17/01/2004">17/01/2004</option>


<script type="text/javascript">
var date, y = 2004; d = new Date(y,0,1);

for (; {
d.setDate(d.getDate() + ( 6 - d.getDay() ) );
if (d.getFullYear() != y) break;

date = ('00' + d.getDate()).slice(-2) + '/' +
('00' + (d.getMonth() + 1)).slice(-2) + '/' +
d.getFullYear();

document.writeln(
'<option value="', date, '">', date, '</option>'
);
d.setDate(d.getDate() + 1);
}
</script>


HTH;
JW



 
Reply With Quote
 
Maarten
Guest
Posts: n/a
 
      01-20-2004
Thanx everybody. Fine to find help here. Maarten - Belgium.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count saturdays and sundays between two dates gunso Javascript 10 05-12-2009 06:41 PM
Re: after saturdays result.. Gram Computer Support 0 01-13-2004 09:10 AM



Advertisments