Modify auto refresh javascript to allow user to select refresh interval

Hi -

Very new to javascript -

Found the following code which works very well refreshing the page - It uses a check box to turn the refresh on or off - which is nice -

However it has a "fixed" refresh interval -

I would like to try to modify this code to allow the user to select the refresh interval from a list box with several possible refresh interval choices -

I have looked but can't find a script with this option -

The existing code is as follows:

<script>


// minutes:seconds
var limit="0:60"

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

function beginRefresh(){

   if (!document.images) {
      return
   }

   var is_hdr_checked = window.document.form_hdr_cbx.cbx_refresh;
   var is_hdr_checked2 = window.document.form_hdr_cbx2.cbx_refresh2;

   if (is_hdr_checked.checked == false) {
        window.status="Page refresh suspended"
      return
   }

      if (is_hdr_checked2.checked == false) {
        window.status="Page refresh suspended"
      return
   }

   if (p_limit==1) {
      window.location.reload()
   } else {
      p_limit-=1
      c_min=Math.floor(p_limit/60)
      c_sec=p_limit%60
      if (c_min!=0) {
         c_time=c_min+" minutes and "+c_sec+" seconds left until page refresh"
      } else {
         c_time=c_sec+" seconds left until page refresh"
      }
      window.status=c_time
      setTimeout("beginRefresh()",1000)
   }
}

window.onload=beginRefresh

//
</script>

All help appreciated -

Thanks -

Richard
rwinnickAsked:
Who is Participating?
 
ZvonkoConnect With a Mentor Systems architectCommented:
Here an example:

<html>
<head>
<title>Zvonko &#42;</title>
<script>

var p_limit=60;

function beginRefresh(){

   if (!document.images) {
      return
   }

   var is_hdr_checked = window.document.form_hdr_cbx.cbx_refresh;
   var is_hdr_checked2 = window.document.form_hdr_cbx2.cbx_refresh2;

   if (is_hdr_checked.checked == false) {
       window.status="Page refresh suspended"
      return
   }

      if (is_hdr_checked2.checked == false) {
       window.status="Page refresh suspended"
      return
   }

   if (p_limit==1) {
      window.location.reload(true)
   } else {
      p_limit-=1
      c_min=Math.floor(p_limit/60)
      c_sec=p_limit%60
      if (c_min!=0) {
         c_time=c_min+" minutes and "+c_sec+" seconds left until page refresh"
      } else {
         c_time=c_sec+" seconds left until page refresh"
      }
      window.status=c_time
      setTimeout("beginRefresh()",1000)
   }
}

window.onload=beginRefresh

//
</script>
</head>
<body>
<form name="form_hdr_cbx">
<select name="limit" onChange="p_limit=this.value">
<option value="30">00:30
<option value="60" selected>01:00
<option value="90">01:30
</select>
<hr>
<input type=checkbox name="cbx_refresh" checked> Suspend1
</form>
<form name="form_hdr_cbx2">
<input type=checkbox name="cbx_refresh2" checked> Suspend2<br>
</form>
</body>
</html>


0
 
rwinnickAuthor Commented:
Hi Zvonko -

Thanks - works perfectly!!

and is exactly what I was trying to accomplish -

Richard
0
 
ZvonkoSystems architectCommented:
You are welcome.
0
All Courses

From novice to tech pro — start learning today.