Results 1 to 3 of 3

Thread: please help!!

  1. #1
    Join Date
    Dec 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default please help!!

    i dont know javascript at all..im just a copy and paster
    i used this script for a countdown timer and workds great with IE but not with firefox..i want to know how to add an if, else statement so that it will just show 5:00 in the scripts place...or if u can just tell me how to make it cross browser compatible then that would be even better
    the site is www.acaiburnfree.com
    and here is the code
    <SCRIPT language=JavaScript>
    //New phone function end

    var sec = 00; // set the seconds
    var min = 5; // set the minutes

    function countDown() {
    sec--;
    if (sec == -01) {
    sec = 59;
    min = min - 1;
    } else {
    min = min;
    }
    if (sec<=9) { sec = "0" + sec; }
    time = (min<=9 ? "0" + min : min) + ":" + sec + "";
    if (document.getElementById) { theTime.innerHTML = time; }
    SD=window.setTimeout("countDown();", 1000);
    if (min == '00' && sec == '00') { sec = "00"; window.clearTimeout(SD); }
    }

    function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
    window.onload = func;
    } else {
    window.onload = function() {
    if (oldonload) {
    oldonload();
    }
    func();
    }
    }
    }

    addLoadEvent(function() {
    countDown();
    });

    </SCRIPT>


    then where i have the timer showing up
    <SPAN id=theTime>

    thanks so much!!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Use document.getElementById, close the span tag (important changes highlighted):

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    //New phone function end
    
    var sec = 00; // set the seconds
    var min = 5; // set the minutes
    
    function countDown() {
    sec--;
    if (sec == -01) {
    sec = 59;
    min = min - 1;
    } else {
    min = min;
    }
    if (sec<=9) { sec = "0" + sec; }
    time = (min<=9 ? "0" + min : min) + ":" + sec + "";
    if (document.getElementById) { document.getElementById('theTime').innerHTML = time; }
    SD=window.setTimeout("countDown();", 1000);
    if (min == '00' && sec == '00') { sec = "00"; window.clearTimeout(SD); }
    }
    
    function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
    window.onload = func;
    } else {
    window.onload = function() {
    if (oldonload) {
    oldonload();
    }
    func();
    }
    }
    }
    
    addLoadEvent(function() {
    countDown();
    });
    
    </script>
    </head>
    <body>
    <span id=theTime></span>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Dec 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    OMG it fixed it!!! thank u soooo much! u rock!

Bookmarks

Posting Permissions

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