1
I have 2 date fields and I will use these dates in a select and I would like a "query" button to appear only when the two fields are filled, follow the current code:
<form method="post" action="">
Início do período:
<input type="text" id="calendarioIni" name="dataInicio">*
Fim do período:
<input type="text" id="calendarioFim" name="dataFim">*
<input type="submit" value="Consultar"/>**
<br><br><br>
<?php if(isset($_POST['dataInicio']) && isset($_POST['dataFim']))
{
$dataIni = $_POST['dataInicio'];
$dataFim = $_POST['dataFim'];
echo $dataIni."<br>";//Teste para verificar o valor nas variáveis que recebem a data via POST
echo $dataFim;
}
?>
</form>
<script>
window.onload = function(){
var dataIni = document.querySelector("#calendarioIni");
var dataFim = document.querySelector("#calendarioFim");
dataIni.addEventListener('input', checaVazio );
dataFim.addEventListener('input', checaVazio );
function checaVazio(){
var botao = document.querySelector("form input[type='submit']");
botao.style.display = dataIni.value && dataFim.value ? "inline" : "none";
}
};
var start = new Date(1997, 12, 01);
var end = new Date(1998, 11, 31) ;
var view = new Date(1997, 12, 01);
$(document).ready(function() {
$('#calendarioIni').datepicker({
endDate: end,
startDate: start,
startView: view
});
});
$(document).ready(function() {
$('#calendarioFim').datepicker({
endDate: end,
startDate: start,
startView: view
});
});
</script>
*calendarioIni and calendarioFim are a datepicker.
**button that you would like to appear only after filling the calendars
What changes should occur so that the button only appears with the dates completed?
i already have a script that defines some attributes of the calendar, it does not have this "type="", I open another block script just for this validation method or I can put inside the same one that I already use?
– V.Avancini
I usually put in separate block
– Ivo Júnior
you could explain better about the reference to jquery?
– V.Avancini
<src="jquery-3.1.0.min. js"></script> I’m using a local file before this block I mentioned in the reply, but you can go to the Jquery website and download or use the address they make available
– Ivo Júnior
and this block I would put before the button?
– V.Avancini
You can put it in the head
– Ivo Júnior
turns out that this is a system I’m working on, it’s full of <script src=" folders.. /vendor/jquery/jquery.min.js"></script>, and has this reference but is in the footer... I tested the code you sent and the button did not open
– V.Avancini
If the jquery you are using is in the footer, this block I passed you must be below the jquery reference.
– Ivo Júnior