Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9089795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:13:37+00:00 2026-06-16T22:13:37+00:00

I was trying to make a JS countdown script that adjusts both the seconds

  • 0

I was trying to make a JS countdown script that adjusts both the seconds to go and the price that has to be paid.

For example:
You will be redirected in 5 seconds or click here to pay 150 to redirect immediately.

So, 30 virtual coins a second.

I have already tried to make it but I suck at JS.

So, what I tried (by copy/pasting other codes found on the internet):

<script type="text/javascript">
function countDown(secs,elem) {
    var element = document.getElementById(elem);
    element.innerHTML = "Please wait for "+secs+" seconds";
    if(secs < 1) {
        clearTimeout(timer);
        location.href='mywebpage.php';
    }
    secs--;
    var timer = setTimeout('countDown('+secs+',"'+elem+'")',1000);

        timeout = 4;
        if(document.getElementById('costs'))
            document.getElementById('costs').innerHTML='&euro; '+(timeout*30);
        document.getElementById('status').innerHTML = formatTime (timeout);
        timeout--;
}
</script>

Then offcourse having the HTML:

<div id="costs"></div>
<div id="status"></div>

<script type="text/javascript">countDown(3000,"status");</script>

I hope someone can help me.

Auto count down, has to redirect when the counter hits zero, has to take off 30 something every second from the second “counter”.

All tips will be appreciated.

Thanks in advance.

Edit:
Note that the countdown works, timeout also works but I don’t know how to link the countdown to the timeout = 4 (the number of the countdown function should be at 4, already tried document.getElementById(‘status’); and stuff like that).

Edit 2:

Fixed!

So, figured it out.

For the people that are also searching for a similar JS:

<script type="text/javascript">
function countDown(secs, ele)
{

    if(secs <= -1)
    {
        location.href = 'rangtest.php'; // No need to kill a timeout it only fires once
    }
    else
    {
        // This is just copying your code, you should fix this to use the targeted ele
        if(document.getElementById('costs'))
            document.getElementById('costs').innerHTML='&euro; '+(secs*30);
        document.getElementById('status').innerHTML = (secs);

        secs--;
        setTimeout( function() { countDown(secs, ele); }, 1000);
    }
}

</script>

Thanks to @Dan Mayor.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:13:38+00:00Added an answer on June 16, 2026 at 10:13 pm

    I’ve always had problems trying to apply arguments to the timer functions which have led me to always define an anonymous function that in turn calls what I am trying to call. Below will need some modification but should help.

    function countDown(secs, ele)
    {
        if(secs <= 0)
        {
            location.href = 'mypage.htm'; // No need to kill a timeout it only fires once
        }
        else
        {
            // This is just copying your code, you should fix this to use the targeted ele
            if(document.getElementById('costs'))
                document.getElementById('costs').innerHTML='&euro; '+(secs*30);
            document.getElementById('status').innerHTML = formatTime (secs);
    
            secs--;
            setTimeout( function() { countDown(secs, ele); }, 1000);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a countdown timer script that takes a number of seconds
I'm trying make an entity with doctrine that has three associations with other entities
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
I'm trying to make a simple app that will display a count down timer
I'm trying to make a countdown timer that plays a sound when it reaches
I am trying to create a countdown timer that counts down for 60 seconds
I'm trying to make countdown timer that resets itself every 60 minutes and wont
Im trying to make a countdown timer run in the background of my activity,
I am trying to make a countdown from a fixed minute like 1:00 to
Trying to make a small countdown timer in my app but it's not working.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.