Please, do not say this has already been answered. It doesn’t work and I’d like some help with it.
javascript test on codebeautify.org
function setTimer() {
setTimeout(stopTimer, 10000);
}
function stopTimer() {
alert('stopTimer');
}
setTimer();
This code executes perfectly at online javascript test site.
MY CODE
in my .xhtml
<h:inputText id="raceTimeId" styleClass="bodyTextMediumLeft" size="8" value="#{hhraMain.racePostTime}" />
<h:commandButton id="reminderId" style="margin: 5px; width: 20px" onclick="clickDateMath()" value="R" />
in my .js file
function clickDateMath() {
let raceHour = document.getElementById('hhraFormId:postHourId').value;
var hourArray = raceHour.split(':');
var intHour = parseInt(hourArray[0]);
if (intHour < 12)
intHour += 12;
const nowDate = new Date();
var nowYear = nowDate.getFullYear();
var nowMonth = nowDate.getMonth();
var nowDayOfMonth = nowDate.getDate();
var nowHour = nowDate.getHours();
const futureDate = new Date(nowYear,nowMonth,nowDayOfMonth,intHour,hourArray[1],1);
var delay = futureDate - nowDate - 60000;
alert('This sets the timeout ' + delay);
setTimeout(displayWarning, delay);
}
function displayWarning() {
alert('displayWarning');
document.getElementById('hhraFormId:warningId').click();
}
The alert in the checkDateMath function executes, but for whatever reason,the function displayWarning does not fire after the expected time delay. The delay specified in the alert is correct for what I’m trying to do. I’m taking the milliseconds difference between two times and then subtracting an extra minute. I want a warning 1 minute before the time submitted to the function.