Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 396
  • Last Modified:

Delay webform autorefresh

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
tnook
Asked:
tnook
  • 4
1 Solution
 
archrajanCommented:
<!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
 
archrajanCommented:
change this line

to


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

its much better
0
 
archrajanCommented:
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
 
tnookAuthor Commented:
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
 
archrajanCommented:
did u check my answeers>
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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