doubts if fields [closed]

2

I have a form where the user can search for a range of dates, or by id, name, nif

I have the following code:

$("#pesquisa").on("submit", function (event) {
    event.preventDefault();

    var key = document.getElementById("key").value;
    alert(key);
    var start = new Date(document.getElementById("datainicio").value);
    var end = new Date(document.getElementById("datafim").value);

    if (key !== "") {
        mostrarinfo();

    }

    var timeDiff = Math.abs(end.getTime() - start.getTime());
    var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));

    alert(diffDays);

    if (((diffDays < 180) {
        $("#estado").hide();

        mostrarinfo();
    } else {
        $("#estado").show();
    }

});

I'm only working for the date, so the key field did not want to search even without entering the date.

HTML code

<form id="pesquisa" class="navbar-form navbar-left" role="search" method="POST"  >
    <div class="form-group">
        <span>KEY:</span>
        <input type="search" class="form-control" placeholder="key"  hidden="hidden" name="key"  id="key" value=""/>                    

        <span>De:</span>
        <input class="form-control"   placeholder="Data inicio"  id="datainicio" hidden="hidden"  name="datainicio" type="date" value="<?php echo $_SESSION['datainicio']; ?>"/>
        <span>a:</span>
        <input class="form-control" placeholder="Data Final" id="datafim" name="datafim"  hidden="hidden" type="date"  value="<?php echo $_SESSION['datafim']; ?>"/>
        <span>Estado:</span>

    </div>

    <button id ="submit" type="submit" class="btn btn-primary">Pesquisar</button><br>
    <label id="estado" style="color:red ; display: none" >Intervalo de datas superior a 180 dias</input>
</form>
    
asked by anonymous 14.09.2015 / 17:16

0 answers