Palemo
Palemo

Reputation: 215

JQuery UI datepicker determine if Saturday clicked

I am using datepicker and if someone selects a Saturday I want it to update a form select with different options - any idea how to do this?

I thought I could use the onSelect function, but all my attempts thus far do not work.

Any help would be much appreciated!

Upvotes: 1

Views: 5205

Answers (4)

Shiva
Shiva

Reputation: 6885

You can do it this way.

$("#TxtStrtDate").datepicker({

    changeMonth: true,

    onSelect: function (selectedDate) {
        var date = $(this).datepicker('getDate');
        var day = date.getUTCDay();
        if (day == '6') {
            alert('its a saturday');

        }

    }
});

The getUTCDay() method returns the day of the week (from 0 to 6) for the specified date, according to universal time.

Note: Sunday is 0, Monday is 1, and so on.

JsFiddle

Upvotes: 2

Defain
Defain

Reputation: 1325

This is how you can get that saturnday is selected. Run your code after selection is confirmed.

var date = $("#datepickerID").datepicker('getDate');
var dayOfWeek = date.getUTCDay();

alert(dayOfWeek);

if(dayOfWeek == "saturnday") {

 // Do the magic

}

Upvotes: 0

Saifuddin Sarker
Saifuddin Sarker

Reputation: 863

Get current date from your datepicker then USE javascript date object: http://www.w3schools.com/jsref/jsref_obj_date.asp

Here is the function to check which day it is

var d = new Date("Your_DATE_FROM_UI_DATEPICKER");

if(d.getDay()==6){
 // Do your task
 }

For you if it is 6. Put if else condition for check it is 6 or not then do your stuff there

Upvotes: 0

murli2308
murli2308

Reputation: 3002

It is very simply Below is code to do that.

function doSomething() {
    var date1 = $('#datepicker').datepicker('getDate');
    var day = date1.getDay();
    if (day == 6) {
        //this is saturday do you code here.
        alert("Saturday");
    }
}

$( "#datepicker" ).datepicker({
    onSelect: doSomething
 });

Here is fiddle http://jsfiddle.net/murli2308/v4327/

Upvotes: 3

Related Questions