What I want to do is that when entering my page, my two default date fields show the current date, these are my fields
<div class="form-group">
<div class="input-group date" id="datetimepicker1">
<input id="fechInicio" name="fechInicio" class="form-control" type="text"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
<div class="form-group">
<div class="input-group date" id="datetimepicker2">
<input id="fechFin" name="fechFin" class="form-control" type="text"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
and this is my code with javascript, what it does is that by clicking on the first calendar in automatic it puts the current date in the two fields, that is achieved by placing useCurrent: true
, in both datetimepicker, also what it does is that it does not allow me to select days after the current date, nor does it allow me to select the days before the date selected in the first calendar
$(document).ready(function(){
validaFechas();
};
function validaFechas(){
$('datetimepicker1').datetimepicker({
locale: 'es',
format: 'L',
useCurrent: true,
format: 'DD/MM/YYYY'
});
$('datetimepicker2').datetimepicker({
locale: 'es',
format: 'L',
useCurrent: true,
format: 'DD/MM/YYYY'
});
$("#datetimepicker1").on("dp.change",function (e){
var fechaInicio = new Date(e.date);
$('#datetimepicker2').data("DateTimePicker").minDate(e.date);
var maximaFechaFin = new Date();
maximaFechaFin.setMinutes(1);
$('#datetimepicker2').data("DateTimePicker").maxDate(maximaFechaFin);
});
$("#datetimepicker2").on("dp.change",function (e)
{
$('#datetimepicker1').data("DateTimePicker").maxDate(e.date);
var maximaFechaInicio = new Date();
var minimoFechaInicio = new Date(maximaFechaInicio.getFullYear(),
maximaFechaInicio.getMonth(), maximaFechaInicio.getDate() -92);
$('#datetimepicker1').data("DateTimePicker").minDate(minimoFechaInicio);
});
$("#fechInicio").keypress(function(evt){evt.preventDefault();})
$("#fechFin").keypress(function(evt){evt.preventDefault();})
}
What I want to do is that by entering my page in automatic they are already showing the current date, I did the following, but it does not work, what it does is that by clicking on the first calendar it displays another calendar on top of which I already have
$(document).ready(function(){
validaFechas();
$("#datetimepicker1").datepicker({
format: 'DD/MM/YYYY',
}).datepicker("setDate", new Date());
};
I also did the following, try to simulate a click on my datetimepicker1, so that when loading the page it will show the dates, but neither does it
$(document).ready(function(){
validaFechas();
document.getElementById("#fechInicio").click();
};
How can I do it? What I'm I missing of? I need your help, thank you.