jQuery datepicker, onSelect won't work

JqueryDatepickerOnselect

Jquery Problem Overview


I can't get onSelect working on my jQuery datepicker.

Heres my code:

<script type="text/javascript">
$(function() {
    $('.date-pick').datePicker( {
        onSelect: function(date) {
            alert(date)
        },
        selectWeek: true,
        inline: true,
        startDate: '01/01/2000',
        firstDay: 1,
    });
});
</script>

It's like it doesn't register the onSelect function. What am I doing wrong?

Jquery Solutions


Solution 1 - Jquery

No comma after the last property.

Semicolon after alert(date);

Case on datepicker (not datePicker)

Check your other uppercase / lowercase for the properties.

$(function() {
    $('.date-pick').datepicker( {
        onSelect: function(date) {
            alert(date);
        },
        selectWeek: true,
        inline: true,
        startDate: '01/01/2000',
        firstDay: 1
    });
});

Solution 2 - Jquery

datePicker's onSelect equivalent is the dateSelected event.

$(function() {
    $('.date-pick').datePicker( {
        selectWeek: true,
        inline: true,
        startDate: '01/01/2000',
        firstDay: 1,
    }).bind('dateSelected', function(e, selectedDate, $td) {
        alert(selectedDate);
    });
});

This page has a good example showing the dateSelected event and other events being bound.

Solution 3 - Jquery

$('.date-picker').datepicker({
    				autoclose : true,
    				todayHighlight : true,
    				clearBtn: true,
    				format: 'yyyy-mm-dd', 
    				onSelect: function(value, date) { 
    	                 alert(123);
    	            },
    				todayBtn: "linked",
    				startView: 0, maxViewMode: 0,minViewMode:0

    			    }).on('changeDate',function(ev){
    				//this is right events ,trust me
                    }
});

Solution 4 - Jquery

The best solution is to set the datepicker defaults

folows the code that I used

$.datepicker.setDefaults({
    onSelect: function () {
        $(this).focus();
        $(this).nextAll('input, button, textarea, a').filter(':first').focus();
    }
});

Solution 5 - Jquery

The function datepicker is case sensitive and all lowercase. The following however works fine for me:

$(document).ready(function() {
  $('.date-pick').datepicker( {
    onSelect: function(date) {
        alert(date);
    },
    selectWeek: true,
    inline: true,
    startDate: '01/01/2000',
    firstDay: 1
  });
});

Solution 6 - Jquery

<script type="text/javascript">
	$(function() {
		$("#datepicker").datepicker({ 
		      onSelect: function(value, date) { 
		         window.location = 'day.jsp' ; 
		      } 
		});
	});
 </script>

<div id="datepicker"></div>

I think you can try this .It works fine .

Solution 7 - Jquery

I have downloaded the datepicker from jqueryui.com/download and I got 1.7.2 version but still onSelect function didn't work. Here is what i had -

$("#datepicker").datepicker();

$("#datepicker").datepicker({ 
      onSelect: function(value, date) { 
         alert('The chosen date is ' + value); 
      } 
});

I found the solution in this page -- https://stackoverflow.com/questions/1274347/problem-with-jquery-datepicker-onselect . Removed the $("#datepicker").datepicker(); once and it worked.

Solution 8 - Jquery

It should be "datepicker", not "datePicker" if you are using the jQuery UI DatePicker plugin. Perhaps, you have a different but similar plugin that doesn't support the select handler.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTommy JakobsenView Question on Stackoverflow
Solution 1 - JqueryAntony CarthyView Answer on Stackoverflow
Solution 2 - JqueryBen KoehlerView Answer on Stackoverflow
Solution 3 - JqueryZ.YView Answer on Stackoverflow
Solution 4 - JqueryItamarView Answer on Stackoverflow
Solution 5 - JquerysamjudsonView Answer on Stackoverflow
Solution 6 - JqueryJudyView Answer on Stackoverflow
Solution 7 - JquerysrilathaView Answer on Stackoverflow
Solution 8 - JquerytvanfossonView Answer on Stackoverflow