Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

forcing the user to select a specific day of the week... 1

Status
Not open for further replies.

secretsquirrel

Programmer
Mar 22, 2001
202
GB
hi!

i've got three dropdowns which represent a date - one for the date, one for the month and one for the year. problem is i need to force people to select a friday!

i'm creating a date object from these 3 fields and then i'm using getDay() to find out which day of the week the user has selected.

this is where i'm getting stuck. if the user selects 23/03/2006 (a thursday), i need the date dropdown to automatically change to 24 (the nearest friday). can anyone suggest a way to do this? i just can't think of a logical way to do it.

many thanks,

ss...



 
Well, this isn't quite your answer, but you can use it to get there:

Code:
 var today = new Date();
 var dayOfWeek = today.getDay(); //returns 0 - 6
 while(dayOfWeek != 5) //[red]5 is Friday[/red]
 {
  today.setDate(today.getDate() + 1);
  dayOfWeek = today.getDay();
 }

 //at this point, "today" equals the next Friday.

You can use a variation of this code to set the date to the values in the drop-down lists and then cycle upward from there until the dayOfWeek is equal to 5.

'hope that helps.

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top