I'm trying to access the value of a datepicker in javascript and no matter what i do i get a value of undefined.
Here are teh things i have tried
function
CustomValidate(sender, args)
{
var datePicker = $find("<%= txtDate.ClientID %>");
alert (datePicker.value);
alert (datePicker.get_Value);
alert (datePicker.get_textBoxValue);
alert (sender.value);
Please can you tell me what i am doing wrong as the datepicker has a date in it: it loads with a default date of today's date.
Here is the aspx for the datepicker
<telerik:RadDatePicker ID="txtDate" runat="server" Height="16px" EnableEmbeddedSkins="False">
<Calendar CellAlign="Center" CellVAlign="Middle" DayNameFormat="FirstLetter" FirstDayOfWeek="Default"
MonthLayout="Layout_7columns_x_6rows" Orientation="RenderInRows" TitleAlign="Center" EnableEmbeddedSkins="False" ShowRowHeaders="false"
NavigationNextImage="~/Images/CalendarSkin/arrowRight.gif"
NavigationPrevImage="~/Images/CalendarSkin/arrowLeft.gif"
FastNavigationNextImage="~/Images/CalendarSkin/fastNavRight.gif"
FastNavigationPrevImage="~/Images/CalendarSkin/fastNavLeft.gif">
</Calendar>
<DatePopupButton HoverImageUrl="~/Images/CalendarSkin/datePickerPopupHover.gif"
ImageUrl="~/Images/CalendarSkin/datePickerPopup.gif" />
<DateInput Height="16px" EnableEmbeddedSkins="False">
</DateInput>
<DatePopupButton HoverImageUrl="~/Images/CalendarSkin/datePickerPopupHover.gif" ImageUrl="~/Images/CalendarSkin/datePickerPopup.gif" />
</telerik:RadDatePicker>
thanks
7 Answers, 1 is accepted
To get or set property values for client API properties, you must call property accessor methods that are named with the get_ and set_ prefixes. For example, to get or set a value for a property such as cancel, you call the get_cancel( ) or set_cancel(...) methods:
var datePicker = $find("<%= txtDate.ClientID %>"); |
datePicker.get_selectedDate(); |
Sincerely yours,
Manuel
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
If you would like to set the date for the picker using the client-side API of the control, you will need to use the set_selectedDate() method instead of the getter.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
When I use your example -
var max = new Date();
var datePicker = $find("<%= dpStartDate.ClientID %>");
datePicker.set_selectedDate() = max;
This is the error message that I get: Object expected------------------
When I tried
var max = new Date();
var datePicker = document.getElementById("<%= dpStartDate.ClientID %>");
datePicker.set_selectedDate(max);
This is the error message that I get: Object doesn't support this method or property------------------
When I tried
var max = new Date();
var datePicker = document.getElementById("<%= dpStartDate.ClientID %>");
datePicker.set_selectedDate() = max;
This is the error message that I get: Cannot assign to a function result--------------------
Can you please provide a working example? Thanks
Try the code snippet below to see whether this helps:
var max = new Date();
max.setDate(max.getDate()+5);
var datePicker = $find("<%= dpStartDate.ClientID %>");
datePicker.set_selectedDate(max);
Regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
any help ??
Please check our client-side API example:
http://demos.telerik.com/aspnet/Prometheus/Calendar/Examples/DatePicker/ClientAPI/DefaultCS.aspx
Kind regards,
Vlad
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.