jquery change event on date calculation -


i add x number of months dropdown (month_number) start date end date calculated , shown correctly:

 $('#start_date').change(function(){  var months = +$('#month_number').val();   var end = new date($(this).val());  end.setmonth(end.getmonth() + months);    $('#end_date').val( (end.getmonth() + 1) + '/' + end.getdate() + '/' + end.getfullyear()) ;  

demo: https://jsfiddle.net/8epztlv2/3/

but want changing dropdown (month_number) end date not changing !

here's fiddle.

$('#start_date, #month_number').change(function() {   var months = $('#month_number').val();   var end = new date($('#start_date').val());   end.setmonth(end.getmonth() + number(months));   $('#end_date').val((end.getmonth() + 1) + '/' + end.getdate() + '/' + end.getfullyear()); }); 

you have add changing event select element. value of end getting $('#start_date').val() instead of $(this).val().


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -