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

1

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

Example user types 4 in 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>");
    }            
});
    
asked by anonymous 08.02.2016 / 18:05

1 answer

2

Here's 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>");
    }   
});
    
08.02.2016 / 18:38