?
Solved

auto refresh every 2 minutes with checkbox

Posted on 2014-08-14
3
Medium Priority
?
1,180 Views
Last Modified: 2014-08-15
Hi,

I need a checkbox, that when a user check it, then the page auto refresh every two minutes and after each refresh the checkbox remains checked until the user uncheck it, then after unchecked the auto refresh stops. Any idea?
0
Comment
Question by:joyacv2
3 Comments
 
LVL 29

Expert Comment

by:sammySeltzer
ID: 40261289
How about this:

<input type="checkbox" name="toggle" value="1"
         onclick="location.href='yourpage.php?tab=<%=tab%>&toggle=' + (cb.checked ? 1 : 0 );"
         <%IF toggle=1 THEN echo "checked" %> 
>

Open in new window

0
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 40261322
<input type="checkbox" name="toggle" value="1" autocomplete="off">

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
if(window.location.hash == "#refresh"){
	$("[name=toggle]").prop("checked",true);
	pageRefresh = setTimeout(function(){window.location.reload()}, 120000);
}

$("[name=toggle]").click(function(){
	if(!$('[name=toggle]').prop('checked')){
		window.location.hash=""
		clearTimeout(pageRefresh);
	}
	else{
		window.location.hash = "refresh";
		pageRefresh = setTimeout(function(){window.location.reload()}, 5000);
	}
})
</script>

Open in new window

0
 
LVL 1

Author Closing Comment

by:joyacv2
ID: 40262768
works perfect!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses
Course of the Month16 days, 14 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question