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

    Passing variable via form


    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

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

    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

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

    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) {
            document.getElementById('countdown').innerHTML = "Time is up!";
    		alert("You will be transfered to another page");
    		window.location = "http://www.google.com"
        } else {
    var countdownTimer = setInterval('secondPassed()', 1000);
    Last edited by PeejAvery; June 19th, 2014 at 07:58 PM. Reason: Added code tags

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002

    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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.