Solved

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

Posted on 2011-02-28
3
310 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now