add 15 days to date using javascript in

Posted by Chilverupavan under Regular Expressions on 4/23/2010 | Views : 5781 | Status : [Member] | Replies : 2
hai friends,,

i have a probelm,,

i have two texboxs like textbox1 and textbox2 and one datepicker for textbox.
when i select date from date picker it has to select date and print to the textbox1.
and when onmousedown the textbox1 date has to add 15 days and print to the textbox2...
how to get that date from textbox1 and add 15 days to that date and dispaly in the textbox2....

this is mycode..............
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<script type="text/javascript" language="javascript">
function test()

var txt1=new Date(document.getElementById("<%= regeggee.ClientID %>"));
var txt2=document.getElementById("<%=regeggee0.ClientID %>");


<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<asp:Label ID="bgcdeat" runat="server" Text="BGC INTIATED DATE:" Font-Bold="True"
ForeColor="White" Font-Names="Verdana" />

<asp:TextBox ID="regeggee" runat="server" Width="200" onmousedown="test();"/>

<asp:HyperLink ID="imgDate4" runat="server" ImageUrl="~/cal.gif">

<asp:Label ID="trgdate" runat="server" Text="TARGET DATE:" Font-Bold="True"
ForeColor="White" Font-Names="Verdana" />

<asp:TextBox ID="regeggee0" runat="server" Width="200" />


need javascript code to add days..................


Posted by: Vuyiswamb on: 4/25/2010 [Member] [MVP] [Administrator] NotApplicable

Well i was passing by preparing to go to church i thought i should give you a server side example that should get you started ,
First i created a Datepicker myself and i hidden it and please note that if you set the visibility of a control to false on design time ,it will not be available in JavaScript that is why i used server side code. here is my markup

<%@ Page Language="C#" MasterPageFile="~/Home.master" AutoEventWireup="true" CodeFile="ForumRules.aspx.cs" Inherits="ForumRules" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"></asp:TextBox>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">.....</asp:LinkButton>
<asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged"
<br />
<asp:TextBox ID="TextBox2" runat="server" AutoPostBack="True"></asp:TextBox><br />
<br />

and here is my server side

using System;

using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ForumRules : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)

protected void LinkButton1_Click(object sender, EventArgs e)
Calendar1.Visible = true;

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
Calendar1.Visible = false;
TextBox1.Text = Calendar1.SelectedDate.ToLongDateString();
TextBox2.Text = Calendar1.SelectedDate.AddDays(15).ToLongDateString();

Thank you for posting at Dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda

Chilverupavan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nitin on: 4/27/2010 [Member] Starter

Try This

//Date 27/04/2010
var date1 = $get(txtDate).value;
var month1 =date1.substring(3,2)
var year1 =date1.substring(6,4)
var d1 = new Date(year1, month1, date1.substring(0, 2));
var chkOutDate = new Date();
d1.setDate(d1.getDate() + 15);
var vDay = d1.getDate();
return vDay ;

Chilverupavan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response