This question is locked. New answers and comments are not allowed.
I am trying to get the value from the DatePicker. But I am getting 'undefined' message. What could be the issue? Here is my code. Also I am trying to get the date difference from 2 DatePickers.
<%
= Html.Telerik().DatePicker()
.Name(
"EndDate")
.ClientEvents(events => events.OnClose(
"DatePicker_onChange")) %>
function DatePicker_onChange() {
// var datepicker = $(this).data('tEndDate');
var date2 = $('#EndDate').data("tEndDate");
alert(date2);
}
4 Answers, 1 is accepted
0
Hi Nara,
You're unable to access the date picker because of the wrong data key. It should be:
Date calculations in JavaScript require some attention and can lead to incorrect results if you don't take Daylight Saving Time into account. The following function calculates the difference between two dates (in ticks):
Please refer to this and similar sites if you need additional information for working with the JavaScript Date object - JavaScript Date Object
I hope this helps.
Best regards,
Tsvetomir Tsonev
the Telerik team
You're unable to access the date picker because of the wrong data key. It should be:
$(this).data('tDatePicker')
The value can be obtained by calling the value() method of the date picker object.
Please refer to this help topic for detailed explanation and examples - DatePicker - Client API and Events
Date calculations in JavaScript require some attention and can lead to incorrect results if you don't take Daylight Saving Time into account. The following function calculates the difference between two dates (in ticks):
function subtractDate(date, dateToSubtract){ var timePerMinute = 60000; var diff = date.getTime() - dateToSubtract; // Compensate for the missing/extra hour during DST change var tzOffsetDiff = date.getTimezoneOffset() - dateToSubtract.getTimezoneOffset(); return diff - (tzOffsetDiff * timePerMinute);};Please refer to this and similar sites if you need additional information for working with the JavaScript Date object - JavaScript Date Object
I hope this helps.
Best regards,
Tsvetomir Tsonev
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
nav100
Top achievements
Rank 1
answered on 04 Jan 2011, 04:02 PM
I have tried using
$(this).data('tDatePicker') but still I couldn't get it working. It doesn't throw any exception. What could possibly wrong?
0
Accepted
Hi Nara,
I've attached a sample project that demonstrates how to access the DatePicker value.
Best regards,
Tsvetomir Tsonev
the Telerik team
I've attached a sample project that demonstrates how to access the DatePicker value.
Best regards,
Tsvetomir Tsonev
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
nav100
Top achievements
Rank 1
answered on 04 Jan 2011, 08:14 PM
Thanks. It worked.