Problem with Event keyup

Asked

Viewed 36 times

1

In this script, I’m picking a start date of a datepicker, and to her I’m adding the week that the guy type with another 5 days. The problem is that he only applies this rule on the first date I select. If I select another start date, it returns the same date as the first selected one. Apparently it saves the first date and stays in 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));
    });
});
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.