I try to develop functions on javascript to allow me, thanks to buttons, to also feed my input type Date.
Entre le <input type="date" id="debut" name="dateDeb" {% if debut is defined %} value={{debut}} {% endif %}/>
et le <input type="date" id="fin" name="dateFin" {% if fin is defined %} value={{fin}} {% endif %}/>
<input type="text" id="debut"/>
<input class="btn btn-primary" type="button" id="aujourdhui" value="Aujourd'hui"/>
<input class="btn btn-primary" type="button" id="semaine" value="Cette semaine"/>
<input class="btn btn-primary" type="button" id="mois" value="Ce mois-ci"/>
For example, at the click of "Today", I want my input date to take the value of the day. So I have this:
// function to update dates at today
$('#aujourdhui').click(function() {
var today = new Date();
var jj = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var aaaa = today.getFullYear();
today = jj + '/' + mm + '/' + aaaa;
alert(today);
document.getElementById("debut").value = today;
});
the "alert" returns the date of the day, but my input remains unchanged. Can someone point me? Thank you !