Click here to Skip to main content
15,943,148 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
~Hi friends,

I have one textbox in which I am going to declare number of days.
At the same time in another date field a date should autogenerate.
Here the newly generated date is based upon one another date field and it has date format as : ex. 16 Jan 2010.

For example :

Text box value : 2
Date1 : 16 Jan 2010
Date2 :---- //This is auto generated.... i.e Date1 + 2

How can I do this with help of javascript?

Please help me.
Updated 16-Nov-10 22:02pm
Dalek Dave 17-Nov-10 4:02am    
Edited for Grammar and Readability.

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        Date 1&nbsp;
        <asp:TextBox ID="TextBox2" runat="server" AutoPostBack="true" ontextchanged="TextBox2_TextChanged"></asp:TextBox>
        <br />
        Date 2&nbsp;        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>

int days = int.Parse(TextBox1.Text);
DateTime dt = Convert.ToDateTime(TextBox2.Text);
TextBox3.Text = dt.AddDays(days).ToString();
Share this answer
Dalek Dave 17-Nov-10 4:03am    
Edited for Code Blocks.
Sandeep Mewara 17-Nov-10 4:21am    
I thought OP was trying this in Javascript!
Text box value : 2
Date1 : 16 Jan 2010
Date2 :---- //This is auto generated.... i.e Date1 + 2

Well, based on this:
1. Hook a onchange event to textbox1
2. based on data entry in textbox, onchange would get fired once done
3. in your onchange event, create a random/todays date and show it in another textbox2 or in a date field
4. at the same time, add two days or any other manipulation to textbox2 date and show this new one in textbox3.

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900