I have the code in JSfiddle. But two things don't happen. Unchecking the box only affects one field (entry_date) and when I submit the form the field expiration_date does not get written to the DB -- the entry_date does. I have jerry rigged the script. I know nothing about JS so any tips would be welcome.
function onCheck(checkbox) {
var entry_date = document.getElementById('entry_date');
var expiration_date = document.getElementById('expiration_date');
entry_date.disabled = checkbox.checked;
expiration_date.disabled = checkbox.checked;
if (checkbox.checked) {
//entry_date.value = new Date().toISOString().substr(0, 10);
//expiration_date.value = new Date().toISOString().substr(0, 10);
entry_date.valueAsDate = new Date();
expiration_date.valueAsDate = new Date();
}
else
entry_date.value = '';
}
Day Guest<br>
<input type="checkbox" id="myCheck" name="dayguest" onclick="onCheck(this);">
<!--If checkbox is checked date box is disabled-->
<br>
<!--Gets today's date and puts it as max-->
<label for="entry_date">Arrival Date</label>
<input type="date" id="entry_date" name="entry_date">
<br>
<label for="entry_date">Departure Date</label>
<input type="date" id="expiration_date" name="expiration_date">
Aucun commentaire:
Enregistrer un commentaire