jQuery: datepicker, alert the dayname of the selected
14,717
Solution 1
The jQueryUI's Datepicker comes with a formatDate
function that can do that for you. If you're using a localized version, it'll show the days in that language too.
onSelect: function(dateText, inst) {
var date = $(this).datepicker('getDate');
alert($.datepicker.formatDate('DD', date));
}
For more information on localization of on Dapicker's utility functions, have a look at http://jqueryui.com/demos/datepicker/.
Solution 2
<script>
$(function() {
$( "#date" ).datepicker({
dateFormat: 'dd/mm/yy',
onSelect: function(dateText, inst) {
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
alert(weekday[inst.getDate().getDay()];
}
});
});
</script>
Solution 3
this will work if you don't mind showing the name of the day in the input box if you dont like it you can use second hidden input (http://jqueryui.com/demos/datepicker/#alt-field)
$(function() {
$( "#date" ).datepicker({
dateFormat: 'DD, d MM, yy',
onSelect: function(dateText, inst) {
var stop = dateText.indexOf(',');
alert( dateText.substring(0, stop));
}
});
});
example at http://jsfiddle.net/aa74R/
Author by
Karem
Updated on June 04, 2022Comments
-
Karem almost 2 years
How can i alert the selected days name? Example 'Monday'.
So when you pick 7th june 2011 it will alert "Tuesday"
<script> $(function() { $( "#date" ).datepicker({ dateFormat: 'dd/mm/yy', onSelect: function(dateText, inst) { // how can i grab the day name of the day, example "Monday" and alert it out? // alert( ? ); } }); }); </script>