doubt if fields

Asked

Viewed 83 times

2

I have a form where the user can search for a date range, 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();
    }

});

Just me working for the date, for the key field I didn’t 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>
  • What does mostrarinfo()? When to call and when to behave differently?

  • will call another function where you fill a table with datatables

  • puts the id key field html

  • @user2964140 if you want to search only for the date because you do not create a flag by checking if the key field is filled in Submit, if it is filled do the search only by key and not by dates...

  • Have a few extra relatives in (((diffDays < 180), let alone (diffDays < 180), has a </input> where there should be a </label> in <label id="estado" style="color:red ; display: none" >Intervalo de datas superior a 180 dias</input>. In closing is </FORm>, change to </form>.

  • 2

    lol was even blind xD thanks worth ;)...another question that already been forgotten from javascript is an if with various conditions . or preference

  • 1

    already vi sufficed to put || and I was to put or

  • Give an Edit to the question and put it to the answer. @user2964140

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.