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

x
?
Solved

Javascript problem with a function value returning:basic

Posted on 2003-03-11
1
Medium Priority
?
250 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
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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

580 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