Link to home
Start Free TrialLog in
Avatar of Patrick Matthews
Patrick MatthewsFlag for United States of America

asked on

"Pause" execution of javascript function for x miliseconds

Easy one for you all. Almost all of my work has been in VBA, VBScript, and SQL, and I need this in JavaScript.

I have the following simple web page.  Basic idea is that each time user clicks update button, the H2 elements update.  Here is what I have so far.  At the point indicated, I want execution to briefly pause (say, 200 miliseconds).

Thanks!

<!DOCTYPE html>
<html>
<body>
<input id="fred" type="submit" value="Update" onclick="changeText()">
<h2 id="h2_1">a</h2>
<h2 id="h2_2">a</h2>
<h2 id="h2_3">a</h2>
<h2 id="h2_4">a</h2>
<h2 id="h2_5">a</h2>
<h2 id="h2_6">a</h2>
<h2 id="h2_7">a</h2>
<h2 id="h2_8">a</h2>
<h2 id="h2_9">a</h2>
<h2 id="h2_10">a</h2>
<h2 id="h2_11">a</h2>
<h2 id="h2_12">a</h2>
<script>
function changeText()
{
 var useH2;
 useH2 = randomIntFromInterval(6, 12);
 for (i = 1; i < 13; i++) {
 document.getElementById("h2_" + i).innerHTML = "x" + i;
 }
 // here is where I want the pause to occur
 document.getElementById("h2_" + useH2).innerHTML = "2017-02-01-" + useH2;
}
function randomIntFromInterval(min,max)
{
    return Math.floor(Math.random()*(max-min+1)+min);
}
</script>
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Patrick Matthews

ASKER

thanks!