Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto Refresh based on Checkbox

Status
Not open for further replies.

AcidHawk

Technical User
Mar 14, 2001
17
0
0
ZA
Hi

I'm trying to auto update a web page every 5 secs based on a check box on a previous page.

Here's my code..

PAGE 1
Code:
print &quot;<form action=./somescript.pl method=post><center>\n&quot;;
print &quot;Enable Auto Update \n&quot;;
print &quot;<input type=\&quot;checkbox\&quot; name=\&quot;autoup\&quot; value=\&quot;on\&quot;><P>\n&quot;; 
print &quot;<input type=\&quot;submit\&quot; value=\&quot;View Summary\&quot;></center>\n&quot;;
print &quot;</form>

This launches a script somescript.pl which I want to update if the check box is checked. If the check box is not checked the page must display but not update..

PAGE 2
Code:
use CGI(&quot;:standard&quot;);
my $cgi = new CGI;
$auto_up = param(&quot;autoup&quot;);

#Set Update Time to 5Secs or 0Secs
if ($auto_up eq 'on') {
	$auto = 5;
} else {
	$auto = -1
}
# Create Header for CGI
print &quot;Content-type:text/html\n\n&quot;; 
print &quot;<META HTTP-EQUIV=\&quot;Refresh\&quot; CONTENT=\&quot;$auto\&quot;>&quot;;
etc...

When I leave the box unchecked the $auto value is set to -1 which will not update - Cool, The problem is that when I check the checkbox the value is set to 5 only once. I think that the problem is that $auto_up is no longer eq to 'on' and the page refreshes once and sets the value of $auto to 5 first then to -1.

My Question is how do I keep the $auto to be 5 forever.. until I decide it must be different?

Many thanks for thousands of great tips ..

AcidHawk ----
Of All the things I've lost in my life it's my mind I miss the most.
 
The problem you've got AcidHawk is that you are refreshing the HTML page - hence you are then resetting the value of the auto_up checkbox to whatever it is stated as in the HTML.

You could:

Use a CGI script to generate the page, then call the script after 5 seconds to generate the page again using the current value of the checkbox. Then when you write the HTML to the screen, set the value of the checkbox according to the auto_up param.

I don't think you can refresh the page without resetting it to the default HTML, this is after all what a refresh is...

Hope that's some help!
Loon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top