0

Necesito realizar que al momento de crear 2 input, cuando seleccione la fecha del primero, el segundo no se pueda seleccionar de la fecha de mas atras.

esto es lo poco que llevo

<table>
                <tr>
                    <th>Fecha de inicio</th>
                    <th>Fecha de termino</th>
                </tr>
                <tr>
                    <th><input type="date" name="dateInicio" value="<?php echo date('Y-m-d'); ?>" min="<?php echo date('Y-m-d'); ?>"/></th>
                    <th><input type="date" name="dateInicio" value="<?php echo date('Y-m-d'); ?>" min="<?php echo date('Y-m-d'); ?>"/></th>
                </tr>
            </table>

1 respuesta 1

0

Vas por buen camino. Puedes hacerlo con javascript.

Intenta:

<table>
<tr>
    <th>Fecha de inicio</th>
    <th>Fecha de termino</th>
</tr>
<tr>
    <td><input type="date" name="dateInicio" id="dateInicio" value="<?php echo date('Y-m-d'); ?>" min="<?php echo date('Y-m-d'); ?>" onchange="handler(event);"/></td>
    <td><input type="date" name="dateTermino" id="dateTermino" value="<?php echo date('Y-m-d'); ?>" min="<?php echo date('Y-m-d'); ?>"/></td>
</tr>
</table>

<script>
function handler(e){
    document.getElementById('dateTermino').value = e.target.value; // actualiza el valor actual
    document.getElementById('dateTermino').min = e.target.value; // setea el nuevo minimo
}
</script>

Usamos el evento onchange del input dateInicio para llamar a la función handler la cual realiza lo que tu quieres..

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.