I have the following problem:
I have this form in HTML
:
<table>
<tr>
<td>Fecha de Salida:</td>
<td><input name="fecha_sali" id="fecha_sali" type="text"></td>
</tr>
<tr>
<td>Días:</td>
<td><input name="fechsa" id="fechsa" type="text" value="60"></td>
</tr>
<tr>
<td>Fecha de pago:</td>
<td><input name="pago" id="total" type="text">
<input class="md-trigger boton" type="button" value="Calcular" onclick="aumenta(this.form)" /></td>
</tr>
And then I use the following code Javascript
to add the 60 days to the checkout date:
function aumenta(frm) {
num=frm.fechsa.value;
f=frm.fecha_sali.value;
// pasaremos la fecha a formato mm/dd/yyyy
f=f.split('/');
f=f[1]+'/'+f[0]+'/'+f[2];
//
hoy=new Date(f);
hoy.setTime(hoy.getTime()+num*24*60*60*1000);
mes=hoy.getMonth()+1;
if(mes<9) mes='0'+mes;
fecha=hoy.getDate()+'/'+mes+'/'+hoy.getFullYear();
frm.total.value=fecha;
}
The problem is that the code Javascript
only works when the input
is type='text'
and when I change it to input type='date'
the calculation doesn't work.
How could I solve that problem?
They
input type="date"
accept them and return a value inYYYY-MM-DD
.With this in mind, you could do the following:
input fecha_sali
getUTC*()
input total
using the correct format.Example:
When you get the value of an input
date
with JS, it comes with this separator format, yyyy-mm-dd , and you are using.split(/)
, try it this way.split(-)
, any questions let me know.