I am trying to update the class of a button from within a class. At the moment the class only updates after the timer() function is finished but I want it to update when the button is pressed. I can see that the classname is changing but it does not update in time.
function reply_click(clicked_id){
id = clicked_id;
var colorSwitch = document.getElementById(id).className;
if(colorSwitch){
colorSwitch = color_check(colorSwitch, id);
console.log(colorSwitch);
console.log(time());
}
}
function time(){
const utcStr = new Date();
return utcStr;
}
//Checks color of pressed button
function color_check(color, id){
if(color == "btnRed"){
alert("Slot already booked!!!!");
}else if(color == "btnYellow"){
alert("You have already booked this slot!!!!!");
}else if(color == "btnGreen"){
alert("Slot booked!!!!!");
color = "btnYellow";
document.getElementById(id).className = color;
var result = timer(new Date());
console.log("1: " + result);
}
return color;
}
//Access python timer class
function timer(time){
let Time = new Date(Date.parse(time));
const timeMin = Time.getMinutes();
console.log(Time);
while (true){
let currentTime = new Date();
currentTime = currentTime.getMinutes();
if((currentTime - timeMin) >= 0.1){
//ajax post
fetch('/background_process_test')
.then(function (response) {
return response.json();
}).then(function (text) {
console.log('GET response:');
console.log(text.greeting);
if(text.greeting == true){
console.log(text.greeting);
//add 45 minute timer to recheck the room is empty
}
});
return false;
}
}
}
I am trying to update the class in colorCheck()