I'm trying to use setTimeout
to perform document.write
after a certain delay after a form is submitted. For now, the delay is a static 3000ms. However, when I try to implement it, document.write
happens instantly. How can I implement setTimeout correctly?
This is for a website. Form submission happens before this block of code runs, and variables are passed from what is submitted.
function findInterval(){
var delay = document.forms["options"]["delay"].value;
min = Math.ceil(min);
max = Math.ceil(max);
var result = Math.floor(Math.random() * (max - min + 1)) + min;
var total = parseInt(delay) + parseInt(result);
setTimeout(document.write(total), 3000);
}
My understanding is that my code should wait 3 seconds, then do document.write(total)
but that's not the case. What am I doing wrong?