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?– Sergio
will call another function where you fill a table with datatables
– usersantos
puts the id key field html
– henriquedpereira
@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...
– Gabriel Rodrigues
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>
.– gustavox
lol was even blind xD thanks worth ;)...another question that already been forgotten from javascript is an if with various conditions . or preference
– usersantos
already vi sufficed to put || and I was to put or
– usersantos
Give an Edit to the question and put it to the answer. @user2964140
– PauloHDSousa