I found a JS that increases the months to a date but only works when the month is January (01), that is, if I put 10/01/2019 and I add 9 months it executes: 10/10/2019.
But if I put 10/05/2019 it executes: 02/10/2053.
Someone can help me with this JS. Thank you!
function Add12(hi){
var obj=document.getElementById('MyDate');
var obj2=document.getElementById('MyDate2');
var val=obj.value;
var date=new Date(val.split('/')[2],(val.split('/')[1]-1+(hi[1]?hi:"0"+hi[0])),val.split('/')[0]);
obj2.value=Format(date.getDate())+'/'+Format((date.getMonth()+1))+'/'+date.getFullYear();
}
function Format(nu){
if (nu<10){ nu='0'+nu; }
return nu;
}
<ul>
<li>Usen 10/01/2019: Funciona!</li>
<li>Usen 10/08/2019: Sale mal!</li>
</ul>
<input id="MyDate" value="" placeholder="DD/MM/AAAA">
<h5>Agregar meses:</h5>
<ul>
<li>
<label for="" onclick="Add12(this.children[0].getAttribute('value'));"><input type="radio" name="mes" value="9">9 meses</label>
<label for="" onclick="Add12(this.children[0].getAttribute('value'));"><input type="radio" name="mes" value="10">10 meses</label>
<label for="" onclick="Add12(this.children[0].getAttribute('value'));"><input type="radio" name="mes" value="12">12 meses</label>
</li>
</ul>
<div id="holi"></div>
<input id="MyDate2" value="" placeholder="Fecha final" >