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.
Asked
Active
Viewed 364 times
0
-
Why don't you just on selection of a date on the first date picker, set the date on the text box? – Pieter Germishuys Aug 15 '12 at 05:28
-
`AutoPostBack` not 'auto pause back'. Maybe you made a spelling mistake. Show your code. – nunespascal Aug 15 '12 at 06:30
1 Answers
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" />
<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