ksumanth Posted December 19, 2012 Share Posted December 19, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/272173-javascript-date-for-next-two-weeks-problem/ Share on other sites More sharing options...
Jessica Posted December 19, 2012 Share Posted December 19, 2012 21 days is three weeks. We aren't psychic. You need to post your code. It sounds like you haven't actually written any Javascript yet for this task. I suggest looking at jQuery. Quote Link to comment https://forums.phpfreaks.com/topic/272173-javascript-date-for-next-two-weeks-problem/#findComment-1400359 Share on other sites More sharing options...
codefossa Posted December 19, 2012 Share Posted December 19, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/272173-javascript-date-for-next-two-weeks-problem/#findComment-1400364 Share on other sites More sharing options...
ksumanth Posted December 26, 2012 Author Share Posted December 26, 2012 (edited) <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 December 26, 2012 by ksumanth Quote Link to comment https://forums.phpfreaks.com/topic/272173-javascript-date-for-next-two-weeks-problem/#findComment-1401274 Share on other sites More sharing options...
codefossa Posted December 27, 2012 Share Posted December 27, 2012 It won't be live because you're using a hardcoded timestamp in JS, so you need a page refresh to make it live. You should create the timestamp within JS if you want to display it multiple times on any page load. Quote Link to comment https://forums.phpfreaks.com/topic/272173-javascript-date-for-next-two-weeks-problem/#findComment-1401427 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.