fareedreg Posted January 12, 2010 Share Posted January 12, 2010 I have two text boxes ... How is this possible that if user enter date in textbox1 and the moment textbox1 lost focus occur the textbox2 will get date of 15 days ahead automatically. Link to comment https://forums.phpfreaks.com/topic/188152-date-problem/ Share on other sites More sharing options...
oni-kun Posted January 12, 2010 Share Posted January 12, 2010 You'd need AJAX to perform this. You can place the function within the onBlur() element with JS. As for your time, you can use strtotime('+15 days'). strtotime Link to comment https://forums.phpfreaks.com/topic/188152-date-problem/#findComment-993329 Share on other sites More sharing options...
lemmin Posted January 12, 2010 Share Posted January 12, 2010 You don't need AJAX to do that. You can use Javascript: <html> <head> <script type="text/javascript"> function setDate(date, txt) { var dates = date.split("/"); var maxDays = 32 - new Date(dates[2], dates[0]-1, 32).getDate(); dates[1] = parseInt(dates[1])+15; if (dates[1] > maxDays) { if (dates[0] == 12) { dates[0] = 1; dates[2] ++; } else dates[0] ++; dates[1] = dates[1]-maxDays; } txt.value = dates[0] + "/" + dates[1] + "/" + dates[2]; } </script> </head> <body> <form> <input type="text" id="txt1" name="txt1" onblur="setDate(this.value, this.nextSibling)" /><input type="text" id="txt2" name="txt2" /> <input type="submit"> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/188152-date-problem/#findComment-993877 Share on other sites More sharing options...
fareedreg Posted January 15, 2010 Author Share Posted January 15, 2010 Thanks a lot for your support You don't need AJAX to do that. You can use Javascript: <html> <head> <script type="text/javascript"> function setDate(date, txt) { var dates = date.split("/"); var maxDays = 32 - new Date(dates[2], dates[0]-1, 32).getDate(); dates[1] = parseInt(dates[1])+15; if (dates[1] > maxDays) { if (dates[0] == 12) { dates[0] = 1; dates[2] ++; } else dates[0] ++; dates[1] = dates[1]-maxDays; } txt.value = dates[0] + "/" + dates[1] + "/" + dates[2]; } </script> </head> <body> <form> <input type="text" id="txt1" name="txt1" onblur="setDate(this.value, this.nextSibling)" /><input type="text" id="txt2" name="txt2" /> <input type="submit"> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/188152-date-problem/#findComment-995398 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.