Solved

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

Posted on 2011-02-28
3
317 Views
Last Modified: 2012-05-11
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
Comment
Question by:willsherwood
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
R-Byter earned 500 total points
ID: 35002705
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
 

Author Comment

by:willsherwood
ID: 35003219
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
 
LVL 14

Expert Comment

by:R-Byter
ID: 35004904
Yup, my mistake on that line, you noticed it well. Thanks for the points.

Regards
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
age from date of birth 4 42
javascript: add id amounts 5 47
asp.net mvc5 6 17
If condition on Html with Asp 11 18
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

810 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