datepicker.formatDate "Object doesn't support this property or method"
Hello,
I'm new to jquery and am experiencing a world of pain getting started. I am attempting to use a datepicker within an ASP.NET application. I'm just trying to get the correct behavior of the control working first.
I have added the following script references and script block to my MasterPage:
<link type="text/css" href="/_css/green/jquery-ui-1.8.5.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="/_scripts/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/_scripts/jquery-ui-1.8.5.custom.min.js"></script>
<script type="text/javascript" src="/_scripts/jquery.ui.datepicker-en-GB.js"></script>
<script type="text/javascript" src="/_scripts/jquery.ui.datepicker-ext.js"></script>
<script type="text/javascript">
$(function() {
$.datepicker.setDefaults($.datepicker.regional['en-GB']);
$.datepicker.setDefaults({
dateFormat: 'dd-M-y',
changeMonth: true,
changeYear: true,
constrainInput: false,
onClose: datePickerOnCloseExt,
});
});
</script>
When a date is selected via the datepicker, the format is correctly displayed in the format dd-M-y.
However, if the user enters a date freehand (not via the datepicker) I would like to parse the input and rewrite it in the date input field in the format dd-M-y.
So, in my jquery.ui.datepicker-ext.js I have a method called datePickerOnCloseExt which is called onClose of the datepicker. It looks like this:
- function datePickerOnCloseExt(dateText, inst) {
if (dateText != '') {
var formattedDate = $.datepicker.formatDate('dd-M-y', dateText);
$(this).val(formattedDate);
}
}
When I run the page that contains the datepicker, I get a runtime error "Object doesn't support this property or method" on the line above where $.datepicker.formatDate() is called. I cannot work out what I am doing wrong. Can anyone please show me the error of my ways?
Many thanks