?
Solved

Javascript problem with a function value returning:basic

Posted on 2003-03-11
1
Medium Priority
?
249 Views
Last Modified: 2010-05-18
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>
0
Comment
Question by:heartguy123
[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
1 Comment
 
LVL 6

Accepted Solution

by:
thomasdodds earned 105 total points
ID: 8112885
<body onload="readCookie();startInterval();" >

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

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
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

764 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