CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2014
    Posts
    1

    Passing variable via form

    Hi!

    I have a timer script. When refreshing the page or going to another page with the same script it starts from zero offcause. I want to pass the remaining time via a hidden for field and then put that in the script as the inintial value. But how?
    I tried doing it with this

    Code:
    document.forms[0].tiden.value = countdownTimer;
    or this

    Code:
    document.getElementById('tiden').value = countdownTimer;
    I tried it with the remainingSeconds variable. Nothing is passed.

    I'm collecting the form value with Response.Write("Time: " & request.Form("tiden"))

    The input looks like this

    Code:
    <input id="tiden" name="tiden" type="hidden" value="">
    and the timer script:

    Code:
    var seconds = 1000;
    function secondPassed() {
        var minutes = Math.round((seconds - 30)/60);
        var remainingSeconds = seconds % 60;
        if (remainingSeconds < 10) {
            remainingSeconds = "0" + remainingSeconds; 
        }
        document.getElementById('countdown').innerHTML = "Time left: " + minutes + ":" + remainingSeconds;
        if (seconds == 0) {
            clearInterval(countdownTimer);
            document.getElementById('countdown').innerHTML = "Time is up!";
    		alert("You will be transfered to another page");
    		window.location = "http://www.google.com"
        } else {
            seconds--;
        }
    }
     
    var countdownTimer = setInterval('secondPassed()', 1000);
    Last edited by PeejAvery; June 19th, 2014 at 07:58 PM. Reason: Added code tags

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Passing variable via form

    In your code countdownTimer is an actual interval, not a variable. If you want to pass the data, then you need to pass the seconds variable.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured