Basically, all I am trying to do is apply one function to two buttons and two inputs. For Example, I'd like to get the current time and put it into the "start-time" input when the "start-time" button is clicked, or vice versa.
In the code below, I am able to get the current time into the 'start' and 'end' inputs by clicking on the parent div, however I am lost on how to make this work using the buttons.
var timeField = document.querySelectorAll(".input-container-dd");
for (let i = 0; i < timeField.length; i++) {
timeField[i].onclick = function getTime() {
var tz_offset = new Date().getTimezoneOffset() * 60000;
var time = new Date(Date.now() - tz_offset).toISOString().slice(11, 16),
timefield = this.children[2];
timefield.value = time;
}
}
<!-- Start Time -->
<div class="input-container-dd">
<label for="time">Start Time</label><br>
<input class="input-field" id="start-time" type="time" name="time">
<button id='start-btn'>Current</button>
</div>
<!-- End Time -->
<div class="input-container-dd">
<label for="time">End Time</label><br>
<input class="input-field" id="end-time" type="time" name="time">
<button id='end-btn'>Current</button>
</div>