?
Solved

Delay webform autorefresh

Posted on 2005-04-02
5
Medium Priority
?
395 Views
Last Modified: 2008-02-01
Hi,

I found a sample of javascript which refreshed a webform every 5 seconds. A side effect of this is that the webform gets reset every 5 seconds... Is there a way of tweaking the code to delay the countdown while a user is entering information into textboxes?

Thanks for your help,
tnook

--------------------------------------------------------------------------------------------------------------------------------------------------------
<script>
<!--
/*
Auto Refresh Page with Time script By JavaScript Kit (javascriptkit.com) Over 200+ free scripts here!
*/

//enter refresh time in "minutes:seconds" Minutes should range from 0 to inifinity. Seconds should range from 0 to 59

var limit="0:05"

                        
if(document.images)
{
    var parselimit=limit.split(":")
    parselimit=parselimit[0]*60+parselimit[1]*1
}

function beginrefresh()
{

  if (!document.images)
      return

  if(parselimit==1)
      window.location.reload()
  else
  {
     parselimit-=1
     curmin=Math.floor(parselimit/60)
     cursec=parselimit%60
                              
     if (curmin!=0)
         curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!"
    else
         curtime=cursec+" seconds left until page refresh!"

    window.status=curtime
    setTimeout("beginrefresh()",1000)
  }
}

window.onload=beginrefresh

//-->
</script>
0
Comment
Question by:tnook
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 25

Accepted Solution

by:
archrajan earned 600 total points
ID: 13688418
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<script>
<!--
/*
Auto Refresh Page with Time script By JavaScript Kit (javascriptkit.com) Over 200+ free scripts here!
*/

//enter refresh time in "minutes:seconds" Minutes should range from 0 to inifinity. Seconds should range from 0 to 59

var limit="0:05"

                   
if(document.images)
{
    var parselimit=limit.split(":")
    parselimit=parselimit[0]*60+parselimit[1]*1
}

function beginrefresh()
{

  if (!document.images)
      return

  if(parselimit==1 && document.getElementById('txt').className == 'go')
      window.location.reload()
  else
  {
     parselimit-=1
     curmin=Math.floor(parselimit/60)
     cursec=parselimit%60
                         
     if (curmin!=0)
         curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!"
    else
         curtime=cursec+" seconds left until page refresh!"

    window.status=curtime
    setTimeout("beginrefresh()",1000)
  }
}

window.onload=beginrefresh

//-->
</script>
<input type = "text" id = "txt" onfocus = "this.className = 'wait'" onblur = "this.className = 'go'">
</BODY>
</HTML>
0
 
LVL 25

Expert Comment

by:archrajan
ID: 13688423
change this line

to


  if(parselimit==1 && document.getElementById('txt').className != 'wait')
      window.location.reload()

its much better
0
 
LVL 25

Expert Comment

by:archrajan
ID: 13688436
but why r u doing this?

the best approach wud be to check if the text field is entered and if entered u can refresh... otherwise do not refresh...
0
 

Author Comment

by:tnook
ID: 13689801
Hi,

Sorry I know virtually nothing about javascript. I've been coding a web application in c# and need this small javascript for just one page.

I need the script to keep refreshing a given web page. However when a user starts to enter something into a text box on the form I want the auto refresh to pause because,  the textbox gets emptied/reset each time the page refreshes and the user might be frustrated.

Cheers
tnook
0
 
LVL 25

Expert Comment

by:archrajan
ID: 13694044
did u check my answeers>
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

765 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