Javascript problem with a function value returning:basic

Hi
I  am new to Javascript, could anyone please help me on this.
This is very important for the project I am doing.

I have to submit a form after a certain time.
I use cookies to avoid time going back to initial stages,in case user refreshes the page.

If the user refreshes,
I am able to retrieve the time value from the cookie also, but I am not able to make the countdown run again..

I would really appreciate any help on this.
Thanks
heart

Below is the code, and its an ASP page.

<html>
<head>
<meta name="GENERATOR" Content="Microsoft Visual Studio.NET 7.0">

<script language=javascript>
function setCookiez(name, value)
{
     document.cookie = name + "=" +escape(value);
}


          var interval = "";
          var iter = 150;
          function startInterval()
          {

               interval = window.setInterval("tTimer()",1000);
               
          }

          function stopInterval()
          {
              window.clearInterval (interval);
              interval="";
          }
          function tTimer()
          {                  
                   document.f.display.value = iter--;


                   if(iter % 10==0)
                   {
                   setCookiez("myTime",iter);
                   }

               if(iter==100)
               {
                    alert("You have 50 seconds left");
               }

                  if (iter == -1)
              {
                  stopInterval();
                  alert ("Your Test Ends");
                  document.test.submit();
              }
}


function readCookie()

{

    var the_cookie = document.cookie;

    var name = unescape(the_cookie);

    var broken_cookie = the_cookie.split("=");
//i split the cookie, here to get the time left
    var name = broken_cookie[2];
     
     if(name==undefined)
     {    
         
          startInterval();
     }
     else
     {
          iter=name;
          alert("Value of iter is: "+iter);
          tTimer();
     }  
}


</script>
</head>


<body onload="readCookie()" >

<p>
     Here we go!!
</p>
          <table>
               <tr>
                    <td>
                         <form name="f" ID="Form2">
                              <input type="text" name="display" value="" ID="Text2">
                         </form>
     
                         <script language="javascript">
                              //startInterval();
                         </script>
                 </td>
               </tr>
          </table>


     <script language=javascript>
          document.writeln("here are cookies: "+document.cookie + "<br>");
     </script>



<script language=javascript>
     readCookie();
</script>
</body>
</html>
heartguy123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

thomasdoddsCommented:
<body onload="readCookie();startInterval();" >

should reset your interval with every page load...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.