This is a migrated thread and some comments may be shown as answers.

can't access datepicker value in javascript

7 Answers 346 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
andieje
Top achievements
Rank 1
andieje asked on 22 Mar 2008, 10:14 PM
Hi

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

Sort by
0
Giuseppe
Telerik team
answered on 24 Mar 2008, 08:14 AM
Hi andieje,

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
0
Rod
Top achievements
Rank 1
answered on 18 Jul 2008, 04:33 PM
I'm trying to set a date to the datepicker control, going off your example, but can't get it to work. Can you provide an example? Thanks!
0
Sebastian
Telerik team
answered on 21 Jul 2008, 07:16 AM
Hi Rod,

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
0
Rod
Top achievements
Rank 1
answered on 21 Jul 2008, 04:09 PM
Stephen - yes of course you need to use the set method.

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
0
Sebastian
Telerik team
answered on 22 Jul 2008, 06:12 AM
Hello Rod,

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
0
Maheshwar
Top achievements
Rank 1
answered on 09 Oct 2008, 08:24 PM
I have tried everytihng in this but i am not able to access the Client API function

any help ??
0
Vlad
Telerik team
answered on 10 Oct 2008, 05:52 AM
Hello Maheshwar,

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.
Tags
Calendar
Asked by
andieje
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Rod
Top achievements
Rank 1
Sebastian
Telerik team
Maheshwar
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or