|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today! |
|
#1
|
|||
|
|||
|
Checking dates
I have a form that I need to check a date field to see if it is a weend day or weekday, and make a select list accordingly.
Something like this: <input name= date value =2006-03-06 onchange=checkDate(this)> fucntion checkDate(obj) How do I take the date in the above form field and check to see if it is a saturday or sunday, and then display the output in an if/then statement? I am more of a php guy! |
|
#2
|
||||
|
||||
|
Here's a quick function I just wrote up... haven't tested it fully, but it seems to work.
Code:
function isWeekend(obj) {
var input_date = new Date(obj.value);
if ( (input_date.getDay()==0) || (input_date.getDay()==6) ) {
return true;
}
return false;
}
Code:
<input type="text" id="date_field" value="March 6, 2006" />
<input type="button" value="Check" onclick="alert(isWeekend(document.getElementById('date_fiel d')));" />
Note, with my function you need to enter the date as you read it in my example... other forms of mm/dd/yy may not work.
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter! DevArticles Forum Moderator "The net is a waste of time, and that's exactly what's right about it." -- William Gibson |
|
#3
|
|||
|
|||
|
Thanks, let me expand on what I want to do. I already have a form setup in an php page that allows users to schedule events. The admin has the option to set weekday hours and weekend hours. The form has a date field, a start time and end time. I need the form to check the date and output the correct start time/end time dropdowns.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Checking dates |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|