0

I have two date pickers in my application. At page load the today's date is displayed in one text field(attached to a date picker) & the other has the date two days from now. What i want to do is, when a date is selected in the first date picker, the date two days ahead of the selected date has to be displayed in the second text box. How can i move to the 'text change method' of the first text box when a date is selected. I have tried the 'auto postback' but it doesn't work.

عثمان غني
  • 2,786
  • 4
  • 52
  • 79
Saku
  • 99
  • 2
  • 2
  • 6

1 Answers1

0
$(function () {
     $(".datePicker").datepicker({
          onSelect: function (dateText, instance) {
               if (this.id == '<%= DateFromTextBox.ClientID  %>') {
                    var date = new Date(Date.parse(dateText));
                    date.setDate(date.getDate() + 2);
                    $("#<%= DateToTextBox.ClientID %>").datepicker("setDate", date);
               }
               __doPostBack(this.name, "");
          }
     });
});

<asp:Label runat="server" AssociatedControlID="DateFromTextBox" Text="From:" />
<asp:TextBox runat="server" ID="DateFromTextBox" CssClass="datePicker" />
&nbsp;
<asp:Label ID="Label1" runat="server" AssociatedControlID="DateToTextBox" Text="To:" />
<asp:TextBox runat="server" ID="DateToTextBox" CssClass="datePicker" />
Yuriy Rozhovetskiy
  • 22,270
  • 4
  • 37
  • 68
  • Thank you very much. How to set a text in a text field inside the 'on select' method of the date picker? I tried $("#textbox1").text="Date"; But this does not work. Can u pls help me? – Saku Aug 15 '12 at 07:39
  • Could you clarify what exactly you want to do? Why you want to set text manually as picker will do this itself? – Yuriy Rozhovetskiy Aug 15 '12 at 07:47
  • It is that I have to set a date on a different text box based on the selected text box, as I have explained in the question – Saku Aug 15 '12 at 07:55