Jump to content

Javascript Date For Next Two Weeks Problem


ksumanth

Recommended Posts

Hello friends,

 

I have two text boxes and one text box i select calendar and i select particular date.After selecting the date In the next text box i have to add from that date to +21 days .

I know how to display from today to next 21 days or weeks. But if i select particular date in that first text box it should calculate automatically +21 days and display second text box

 

Thanks in advance

Link to comment
Share on other sites

Get a timestamp for the date you want to go from. (new Date())

Add the time on to it. (21 days * 24 hours * 60 minutes * 60 seconds * 1000 milliseconds)

Get new date, the get* functions like .getFullYear() and .getMonth() will give you the info you need from it.

 

Note: Javascript goes by millisecond timestamps, not seconds. This mean's you need to multiply or divide by 1000 to send between PHP and JS (and back).

 

Give it a shot and I'll be more willing to help. This should get ya in the right direction anyways.

Link to comment
Share on other sites

<script type="text/javascript">

function myFunction(e)

{

e.blur();

var today=new Date();

document.forms['cal2']['end_date'].value='<?=date('d M Y', strtotime('+21 days'));?>';

}

</script>

<form name="cal2" method="post" action="">

<table width="100%" border="0" cellspacing="0" cellpadding="5">

<tr> <td width="10%" class="redtxt"> Start Date: </td>

<td width="20%"><input class="iselect" type="text" size="20" id="startdate" style="margin-left:7px;" name="startdate" required="true" onfocus="myFunction(this);"

value=""/>

<a href="javascript:showCal('Calendar1')"><small><B><img src="images/calendar.gif" webstripperwas="images/calendar.gif" width="16" height="16" border="0" /></B></small></a>

</td>

<td width="10%" class="redtxt">End Date: </td>

<td width="38%">

<input type="text" name="end_date" id="end_date" value=""/>

</td>

<td width="1%" > </td>

</tr>

</form>

 

This is the function i am using if i select any date from first textbox from that day to 21 days have to calcuate and display in second textbox

Thanks

Edited by ksumanth
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.