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

Setting the raddatepicker date in javascript

5 Answers 599 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Akki
Top achievements
Rank 1
Akki asked on 19 Feb 2013, 11:22 AM

Hi,

I am using raddatepicker for selecting the dates. my scenario when i select the startdate , on click of enddate raddatepicker, the start date value should be pre-populated. I am using javascript to achieve this function. But i am unable to achieve the same. Below is the code.

I am passing the clientId because the raddatepicker is in userControl and i am calling the javascript method in parent page.

Problem is when i am passing clientId it is always going as string.  Let me know if anything i need to do.

 <telerik:RadDatePicker ID="rdDPStartDate" runat="server" Height="20px" onclick=" def(this, 'acd' );"
                    Width="223px">
                </telerik:RadDatePicker>
                <br />
       
            <div id="divEndDatePicker" class="DivTxtBox">
                <telerik:RadDatePicker ID="rdDpEndDate" runat="server" value="Set Date"
                    onclick=" setdate(this,'<%=rdDPStartDate.ClientID %>');" Height="20px" Width="223px">
                </telerik:RadDatePicker>
               

function setdate( start,end) {debugger;
          dateVar = new Date();
         var sd =  $find('end');
         var startDate = sd.get_selectedDate();
         var endDate = $find(start.Id).set_selectedDate(startDate);
//          varDate = datePicker.get_selectedDate();
//          
//          endDatePicker.set_selectedDate(varDate);
      }

5 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 22 Feb 2013, 09:13 AM
Hi,

The argument passed to the setdate method is passed as a string and this is expected. However, you should not enclose the passed parameter in additional quotes, because thus you will not pass the value of the variable but its name. With this code you are always searching for control with name "end" and because such control does not exist $find() always return null.

Try to remove the quotes and you should succeed.


unction setdate( start,end) {debugger;
     dateVar = new Date();
     var sd =  $find(end);
     var startDate = sd.get_selectedDate();
     var endDate = $find(start.Id).set_selectedDate(startDate);
}

Kind regards,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Akki
Top achievements
Rank 1
answered on 23 Feb 2013, 10:30 AM
Hi Andrey,

If i remove the quote there will be script error, method wont be called. Do i need to do any workaround for this ?

Regards,
Akki
0
Andrey
Telerik team
answered on 28 Feb 2013, 07:06 AM
Hi,

If you do not remove the quotes you are trying to find a control with ID="end". Based on the code snippet I do not see such control in your code. Could you remove the quotes and report the error which is thrown?

Additionally, what is the purpose of the OnClick event in the second RadDatePicker? If you want to get the selected data you could use the client-side OnDateSelected event of RadDatePicker. Thus the control will pass all the required arguments and you will be able to get the new date from the arguments. You could check this online demo application for more information on the different events supported by RadDatePicker.

Greetings,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Akki
Top achievements
Rank 1
answered on 02 Mar 2013, 07:07 PM

Hi Andrey,

Error it says is "Syntax Error ".

Andrey Basically, i am trying to achieve following.

There are two raddatepicker controls

one to select start Date and other one to select endate.

After selecting start Date , i will click on box(textbox) in raddatepicker.  it  should populate start date. Can u help me on how to achieve this  ??

Regards,
Akki

0
Andrey
Telerik team
answered on 07 Mar 2013, 07:06 AM
Hi,

If I understand correctly what you want to achieve is the default behavior of RadDatePicker. You could check this online demo application for verification of the behavior. When you click on the button right to the dateinput you choose the date and this date is automatically populated in the dateinput.

Regards,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Calendar
Asked by
Akki
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Akki
Top achievements
Rank 1
Share this question
or