Chris Bowyer
Chris Bowyer

Reputation: 81

JavaScript - Show/Hide Without Refreshing Page

Can anyone help? I want to only show the script output if a particular application variable is true, without refreshing the page, as initially, the application variable could be false

<body>
<div id="output"></div>
<script type="text/javascript">
var quotes = new Array(
'Quote 1',
'Quote 2',
'Quote 3'
);
function rotate() {
    quote = quotes.shift();
    quotes.push(quote);
    document.getElementById('output').innerHTML = quote;
    setTimeout("rotate()", 2000);
}
rotate();
</script>
</body>

Upvotes: 1

Views: 385

Answers (1)

mbxtr
mbxtr

Reputation: 2313

You'll want to use setInterval instead of setTimeout. Something like this:

function showQuotes()
{
    if(someVariable)
    {
        quote = quotes.shift();
        quotes.push(quote);
        document.getElementById('output').innerHTML = quote;
    }
}
setInterval("showQuotes()",2000);

Upvotes: 1

Related Questions