update two input dates automatically?

0

I need to realize that when creating 2 input, when you select the date of the first, the second can not be selected from the date before.

this is how little I have

<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>
    
asked by DeathInWhite 26.07.2018 в 21:22
source

1 answer

0

You're on the right track. You can do it with javascript.

Try:

<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>

We use the event onchange of the input dateInicio to call the function handler which performs what you want ..

    
answered by 28.07.2018 / 21:07
source