Problem with event keyup

1

In this script, I'm getting a start date from datepicker , and I'm adding the week that the guy types in with another 5 days. The problem is that it only applies this rule on the first date that I select. If I select another start date, it returns the same date as the first date selected. Apparently it writes the first date and stays on it.

$(document).ready(function(){
    $("#semanas").keyup(function( event ){
        var date = $('#data-inicio').val();
        var semanas = ($(this).val());
        var diaSeg = 1000 * 60 * 60 * 24;
        var total = (diaSeg * 7) * semanas + 432000000;
        total = total / diaSeg;
        date = date.split("/").reverse().join("-");
        date = new Date(date);
        var dia = new Date(date.getFullYear(), date.getMonth(), date.getDay() + total);
        $("#data-retorno").datepicker('setDate', new Date(dia));
    });
});
    
asked by anonymous 06.05.2015 / 20:44

0 answers