Newbie - please help - countdown function

Discussion in 'JavaScript' started by k3ndr4, Oct 6, 2008.

  1. #1
    I am trying to create a navigation page that will go to a selected url in 5 seconds after clicking the "go in 5" button. After the user clicks the button its text should show the passing time, i.e. it should say "Go in 5", "Go in 4", "Go in 3", etc. After the URL has been loadad it should say "Go in 5" again.

    I am getting a runtime error when I run this. Any idea why?

    Code below:

    <html>

    <head>
    <title>Navigator</title>
    <script type="text/javascript">
    function loadurl() {
    var loadedurl = document.navigate.entered_url.value;

    if (loadedurl.length > 0)

    {parent.document.frames['content'].location.href=("http://" + loadedurl);} // load entered_url into content frame

    else
    {parent.document.frames['content'].location.href="http://www.pitt.edu"; // if no entered_url, load www.pitt.edu into content frame
    }
    }

    function go() {
    }

    var time = 5*1000;
    function countDown() {
    time = time - 1000;
    if (time <= 0) parent.document.frames['content'].location.reload(); // load entered_url into content frame

    else {
    setTimeout(countDown, 1000);
    document.getElementById("time-left").innerHTML = (time/1000).toFixed(0);
    }
    }

    </script>

    </head>

    <base target="content">

    <form name="navigate">
    <body style="background: blue;">

    <input type="button" value="Back" onclick="history.go(-1);return true;">

    <input type="button" value="Forward" onclick="history.go(1);return true;">

    <input type="text" name="entered_url" size="100">

    <input type="button" value="Go" onclick="loadurl()" />

    <input type="button" value="Go in 5" id="time-left" onclick="countDown()" />

    </body>

    </form>

    </html>
     
    k3ndr4, Oct 6, 2008 IP
  2. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Don't have the time to fix your code, but maybe you'll find this solution useful. Good luck ;)
     
    xlcho, Oct 7, 2008 IP
  3. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #3
    you can't set innerHTML on a button element, it has none. set the value instead:
    document.getElementById("time-left").setAttribute("value", (time/1000).toFixed(0));
    Code (markup):
    this would not have caused an error though

    i'm getting
    parent.document.frames is undefined
    Line 25

    which is fair enough, i dont have your frameset :)
     
    dimitar christoff, Oct 7, 2008 IP
  4. k3ndr4

    k3ndr4 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thank you! It works now. Much appreciate the help!
     
    k3ndr4, Oct 7, 2008 IP