How do I add a month to the current date with jquery

Asked

Viewed 46 times

1

Good afternoon, How do I add a month to the current date:

Example the user types 4 in the input qtdParcela:

var _data = new Date();
$("#qtdeParcela").on("change", function () {

    var _qtde = $(this).val();
    for (var i = 0; i < _qtde; i++) {
        $("#divParcela").append("<div class='col-xs-6'> <label>Vencimento - parcela " + parseInt(i + 1) + "</label> <input type='text' id='' value='" + $.datepicker.formatDate('dd/mm/yy', new Date())  + "' class='form-control' /></div> <div class='col-xs-6'><label>Valor - parcela " + parseInt(i + 1) + "</label><input type='text' id='' value='' class='form-control' /></div>");
    }            
});

1 answer

2


Follows the answer:

var _data = new Date();
$("#qtdeParcela").on("change", function () {

var _qtde = 5
    for (var i = 0; i < _qtde; i++) {
        var new_date = new Date()
        new_date.setMonth(new_date.getMonth() + i)

        $("#divParcela").append("<div class='col-xs-6'> <label>Vencimento - parcela " + parseInt(i + 1) + "</label> <input type='text' id='' value='" + $.datepicker.formatDate('dd/mm/yy', new_date)  + "' class='form-control' /></div> <div class='col-xs-6'><label>Valor - parcela " + parseInt(i + 1) + "</label><input type='text' id='' value='' class='form-control' /></div>");
    }   
});

Browser other questions tagged

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