0

I need some help with a part of my program which is suppose to time out. I have a key pad which allows 4 digits to be input then passes this code to another function. I needed a timer after the 4th digit for 1 second so the page will display the result before sending the key and clearing the screen. This is the original part that works. setTimeout(alarm,1000); but when I add the function to send the key it stops working

    if(code.value.length == 4){
    document.getElementById("message").style.display = "block";
    setTimeout(alarm(code.value),1000); 
}
}
function alarm(code){
        alert(code);
        emptyCode();
}

I have read that I cannot put a function within the timeout script so is there another way to do this

  • 1
    Use callback function `setTimeout(function() { alarm(ode.value); }, 1000);` – Tushar Mar 22 '17 at 06:47
  • 2
    You can also use `setTimeout(alarm, 1000, code.value);` see [Docs](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout) – Satpal Mar 22 '17 at 06:48
  • Great thank both worked, spent ages on this –  Mar 22 '17 at 06:53

0 Answers0