1

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!

  • awesome - that tells me they have selected Saturday, but then how do I change the form select values to represent that. Basically for all days during the week is a set value of options, but the options narrow if a Saturday...
Palemo
  • 217
  • 1
  • 5
  • 19

4 Answers4

3

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/

murli2308
  • 2,976
  • 4
  • 26
  • 47
2

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

Shiva
  • 6,677
  • 4
  • 36
  • 61
0

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

}
Defain
  • 1,335
  • 1
  • 10
  • 14
  • How does this answer OP's question? – urbz Aug 06 '14 at 06:45
  • It gets the selected day. Just need to add if the day is saturnday which is basic if clause – Defain Aug 06 '14 at 06:46
  • awesome - that tells me they have selected Saturday, but then how do I change the form select values to represent that. Basically for all days during the week is a set value of options, but the options narrow if a Saturday... – Palemo Aug 06 '14 at 06:52
  • You cannot update the select in // Do the magic section? Or are you asking how to change select fields? – Defain Aug 06 '14 at 06:58
0

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

Saifuddin Sarker
  • 853
  • 3
  • 8
  • 26