1

HTML

<body onload="JavaScript:timedRefresh(10000);">
    <input type="checkbox" checked="checked" name="autoRefreshCheckboxes" >Auto Refresh</input>
</body>

JS

  function timedRefresh(timeoutPeriod) {
        if ($("input[name=autoRefreshCheckboxes]").is(":checked")) {
            setTimeout("location.reload(true);", timeoutPeriod);
        }
    }

How can I make the checkbox work?

It seems that when the <body> loads, it takes the state of the checkbox, and ignores the state of the checkbox when the script is run.
thanks in advance!

1 Answer 1

2

Try using setInterval instead.

function timedRefresh(timeoutPeriod) {
    var interval = setInterval(refreshPage, timeoutPeriod);
}

function refreshPage() {
    if ($("input[name=autoRefreshCheckboxes]").is(":checked")) {
        location.reload(true);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.