jQuery/JavaScript function not updating textbox -
i'm using bootstrap datepicker: https://github.com/eternicode/bootstrap-datepicker
i have attached 2 boxes - invdate , invduedate - , pops ok, , sets dates etc fine.
i have drop down box though, when selected, want take date in invdate box, , add val() of dropdownlist invdate, , populate invduedate.
however, cannot seem invduedate change it's date (does nothing) - dropdown box trigger function, line doesn't appear anything:
$("#invduedate").datepicker("setdate", duedate);
:
html is:
<div class="editor-label"> <label for="invdate">invdate</label> </div> <div class="editor-field"> <input class="textbox datepicker" data-val="true" data-val-date="the field invdate must date." data-val-required="the invdate field required." id="invdate" name="invdate" type="text" value="02 may 2013" /> <span class="field-validation-valid" data-valmsg-for="invdate" data-valmsg-replace="true"></span> </div> <div class="editor-label"> <label for="terms">terms</label> </div> <div class="editor-field"> <select id="terms" name="terms"><option value="0">due on invoice date</option> <option value="7">net 7 days</option> <option value="14">net 14 days</option> <option value="21">net 21 days</option> <option value="28">net 28 days</option> <option value="45">net 45 days</option> <option value="60">net 60 days</option> </select> </div> <div class="editor-label"> <label for="invduedate">invduedate</label> </div> <div class="editor-field"> <input class="textbox datepicker" data-val="true" data-val-date="the field invduedate must date." data-val-required="the invduedate field required." id="invduedate" name="invduedate" type="text" value="02 may 2013" /> <span class="field-validation-valid" data-valmsg-for="invduedate" data-valmsg-replace="true"></span> </div>
my jquery/javascript is:
<script type="text/javascript"> $(document).ready(function () { $("#terms").change(function () { var invdate = new date(); var duedate = new date(); invdate = $("#invdate").val(); var net = $("#terms").val(); duedate.setdate(invdate.getdate() + net); $("#invduedate").datepicker("setdate", duedate); }); }); </script>
is obvious i'm going wrong?
update show working code
var start_date = new date($('#invdate').val()); var duration = parseint($('#terms').val()); var end_date = new date(); end_date.setdate(start_date.getdate() + duration); $("#invduedate").datepicker("setdate", end_date);
i think date not correctly formatted, see :
var invdate = new date();
and it's replaced
$('#invdate').val();
but should :
var invdate = new date($('#invdate').val());
or (as zeroflagl commented)
var invdate = $('#invdate').datepicker('getdate'); //gives date object
Comments
Post a Comment