Change field Automatically after filled in

2

I have a form:

    <div class="span12" style="padding: 10px;">
        <form action="<?php echo base_url()?>index.php/chamadas" method="get">
        <div class="span2">
            <label for="">Data Inicial:</label>
            <input type="date" name="dataInicial" class="span12" />
        </div>
        <div class="span2">
            <label for="">Data Final:</label>
            <input type="date" name="dataFinal" class="span12" />
        </div>
        <div class="span2">
            <label for="">&nbsp;</label>
            <button class="btn btn-inverse span12"><i class="icon-print icon-white"></i> Filtrar</button>
        </div>
        </form>
    </div>

I would like to fill in the start date, I will automatically go to the other end date field. Can someone help me? Many thanks!

    
asked by anonymous 12.06.2015 / 00:06

1 answer

4

You just need to hear the change event and copy the values from one to the other. So for example:

var inicial = document.querySelector('[name="dataInicial"]');
var final = document.querySelector('[name="dataFinal"]');

inicial.addEventListener('change', function () {
    final.value = this.value;
});

jsFiddle: link

    
12.06.2015 / 00:11