I have two datetime-local input star time is for user changeable and the other one is read-only and I want to update that field by jquery.
<input class="form-control" type="datetime-local" name="deliveryTime" id="DeliveryTime" required>
<input class="form-control" type="datetime-local" name="deliveryTimeEnd" id="DeliveryTimeEnd" readonly>
$("#DeliveryTime").on("change", function() {
var startTime = $("#DeliveryTime").val();
startTime.setHours(startTime.getHours()+2);
alert(startTime);
$("#DeliveryTimeEnd").val(startTime);
});
2
Answers
first chnage the startTime in datetime format like below code and then get the hours
Complete code is:
In the end it was not quite as trivial as I assumed in the beginning. Here is a snippet that sets the second datetime input to a time 2 hours after the time of the first input: