php - Date addition formula javascript -


i working on invoice generation program in php. in using datetimepicker use invoice generation date , due date. want due date field auto-filled adding specific value invoice generation date feild. following html :

<div class = "col-lg-4">                 <select id = "invoice_duration"  class="form-control input-group placeholder">                     <option>10</option>                     <option>20</option>                     <option>30</option>                     <option>40</option>                     <option>50</option>                     <option>50</option>                 </select>                 </div><br><br>                  <div class = "col-lg-6">                     <h4> invoice date </h4>                      <div class="input-append date datetimepicker">                       <input id = "invoice_date" style = "height : 35px;" style = "height : 30px;" style = "height : 30px;"  type="text" name = "invoice_date">                       <span style = "height : 35px;" class="add-on">                         <i style = "padding-top:5px;" data-time-icon="fa fa-time" data-date-icon="fa fa-calendar"></i>                       </span>                     </div>                                       </div>                   <div class = "col-lg-6">                 <h4> due date </h4>                     <div class="input-append date datetimepicker">                         <input id = "due_date" style = "height : 35px;" style = "height : 30px;"  type="text" name = "due_date">                         <span style = "height : 35px;" class="add-on">                             <i style = "padding-top:5px;" data-time-icon="fa fa-time" data-date-icon="fa fa-calendar"></i>                         </span>                     </div>                 </div> 

and script follow :

<script>     $( "#due_date" ).click(function() {          var invoice_date = $("#invoice_date").val();         var invoice_duration = $("#invoice_duration").val();          var splited_invoice_date = invoice_date.split("/");         var day = splited_invoice_date[0];         var month = splited_invoice_date[1];         var year = splited_invoice_date[2];         var total_days = (+year_days) + (+month_days) + (+days);         alert('day :' +day+ 'month :' +month+ 'year :' +year);          }); 

using getting alert giving me segregated date. there easy of adding value "select" field , adding invoice_generation_date put in due_date field.

basically want date addition formula. sorry if ambiguous.

thanks in advance.

i trigger event on change of previous field, not enter click.

the easiest way add days in js use seconds in day , use formatting primitives.

something should work:

$("#invoice_date").change(function(){    var invoice_date = $("#invoice_date").val();    var invoice_duration = parseint($("#invoice_duration").val(),10);     var d = new date(invoice_date).gettime()+(invoice_duration*24*60*60*1000);    d = new date(d);    var dformatted =  d.getdate() + '/' + (d.getmonth()+1) + '/' + d.getfullyear();     $("#due_date").val(dformatted).trigger('click');  }); 

the click trigger @ end open cal popout. can remove if don't want happen automatically.

simpler fiddle: http://jsfiddle.net/16gov1ms/1/


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -