I wrote a function called formatAMPM that finds the current time. I want to call the this function when I click on the object named buttonfifteenMins. But I didn't succeed.
I want to update the value of a textbox according to the result from here
function formatAMPM(date) {
var hours = date.getHours();
var minutes = date.getMinutes();
var ampm = hours >= 12 ? 'pm' : 'am';
hours = hours % 12;
hours = hours ? hours : 12;
minutes = minutes < 10 ? '0' + minutes : minutes;
var strTime = hours + ':' + minutes + ' ' + ampm;
return strTime;
}
var input = document.getElementById('dateTimeRange');
var buttonfifteenMins = document.getElementById('fifteenMins');
buttonfifteenMins.onclick = function() {
input.value = formatAMPM(new Date);
};
<input type="text" id="dateTimeRange" />
<button type="button" id="fifteenMins">15 min</button>