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 7846275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:31:39+00:00 2026-06-02T17:31:39+00:00

I have to create a countdown timer for a bidding website. The timer works

  • 0

I have to create a countdown timer for a bidding website. The timer works properly when I put it outside of the while loop. However, id does not work inside the loop. What am I doing wrong? Here is my code:

<script>
var before=""
var current="ended"
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countdown(yr,m,d,id){
theyear=yr;themonth=m;theday=d
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[m-1]+" "+d+", "+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
if(dday==0&&dhour==0&&dmin==0&&dsec==0){
document.getElementById(id).value=current
return
}
else
document.getElementById(id).value="Only "+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left "+before
setTimeout("countdown(theyear,themonth,theday,id)",1000)
}
</script>
<?php 
include('../connection.php');
    $rs = mysql_query("select * from datepic") or die(mysql_error());

    if(mysql_num_rows($rs)){

        while($row = mysql_fetch_array($rs))
        {
            $date = str_replace('-',',',$row['date']);

            echo '<input type="text" id="'.$row['id'].'" size=80>';
            ?>
            <script>
                countdown(<?php echo $date.','.$row['id'];?>)

            </script>


            <?php           

        }
    }

?>
  • 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-02T17:31:43+00:00Added an answer on June 2, 2026 at 5:31 pm

    change setTimeout with this:

    setTimeout(function(){countdown(theyear,themonth,theday,id);},1000)
    

    you can make your function to jQuery function like that:

    jQuery.fn.countdown = function(yr,m,d){
       $that = $(this);
       theyear=yr;themonth=m;theday=d
       var today=new Date()
       var todayy=today.getYear()
       if (todayy < 1000)
          todayy+=1900
       var todaym=today.getMonth()
       var todayd=today.getDate()
       var todayh=today.getHours()
       var todaymin=today.getMinutes()
       var todaysec=today.getSeconds()
       var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
       futurestring=montharray[m-1]+" "+d+", "+yr
       dd=Date.parse(futurestring)-Date.parse(todaystring)
       dday=Math.floor(dd/(60*60*1000*24)*1)
       dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
       dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
       dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
       if(dday==0 && dhour==0 && dmin==0 && dsec==0){
          $that.val(current);
          return
       }
       else
         $that.val("Only "+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds   left "+before);
     setTimeout(function(){ $that.countdown(theyear,themonth,theday);},1000)
    }
    
    <?php 
    include('../connection.php');
        $rs = mysql_query("select * from datepic") or die(mysql_error());
    
        if(mysql_num_rows($rs)){
    
            while($row = mysql_fetch_array($rs))
            {
                $date = str_replace('-',',',$row['date']);
    
                echo '<input type="text" id="'.$row['id'].'" size=80>';
                ?>
                <script>
                    $("?php echo $row['id'] ?>").countdown(<?php echo $date?>);
    
                </script>
    
    
                <?php           
    
            }
        }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a javascript countdown timer; I have a string that
I have built a voucher website, where each voucher has a countdown timer. When
I have created an application.in the app i start a countdown timer and save
I have developed a Count Down Timer and I am not sure how to
I'm trying to create a countdown timer that's based on a time on the
I am implementing a countdown timer. I have a TextBlock which is showing the
I create my multiple timer countdown from easy or simple script. entire code The
I've appropriated some code to create a countdown timer for the launch of a
I have been trying for half a day to loop this countdown function. I
I have a timer that I want to start an AsyncTask when the countdown

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.