• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

JS: cancel a pending page REFRESH if viewer types in TEXTAREA field

We have the following header refresh to auto-refresh after 10 minutes,

<meta http-equiv="refresh" content="600" />

but we want to cancel that refresh if focus (click into) is set to the main textarea on the page (thus a refresh would not seemingly asynchronously foil the viewer's in-progress typing into the textarea prior to SUBMITting).

1.  Is there a JS way to undo the header tag?
2. (if not) is there an alternate way to set a countdown in JS that refreshes on timeout, and thus clicking into the textarea could cancel that countdown somehow
0
willsherwood
Asked:
willsherwood
  • 2
1 Solution
 
R-ByterCommented:
Remove that meta refresh line from the html and put this code inside <head> tags:

<script type="text/javascript">
var timer;
function sto(){
     timer = setTimeout("RefreshPage()",3000);
}
function RefreshPage() {
     window.location = "link to your page";
}
function cto() {
     clearTimeout(timer);
}
</script>

Open in new window


Then put this at your textarea for example:

<textarea name="ta1" id="ta1" cols="10" rows="5" onfocus="RefreshPage()"></textarea>

Open in new window


Regards
0
 
willsherwoodAuthor Commented:
i think this is what i need.  super!
one clarification:    in order to stop the refreshing once focus was there,  i think in the textarea  i would want   a call to cto() .   does that make sense to use  cto() instead of  RefreshPage() ?

thanks
0
 
R-ByterCommented:
Yup, my mistake on that line, you noticed it well. Thanks for the points.

Regards
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now