Question

I am currently trying to fill a html table with several counters, one underneath the other, to show days past since an incident. Thanks to the internet, i ended up with this script:

    <script language="JavaScript1.2" type="text/javascript">function
     setcountup(theyear,themonth,theday){
     yr=theyear;mo=themonth;da=theday
     }

   //////////CONFIGURE THE countup SCRIPT HERE//////////////////

   //STEP 1: Configure the date to count up from, in the format year, month, day:
   //This date should be less than today
   setcountup(2012,9,19)

   //STEP 2: Configure text to be attached to count up
   var displaymessage=""


   //STEP 3: Configure the below 5 variables to set the width, height, background color,       
   and text style of the countup area
   var countupwidth='90%'
   var countupheight='40px' //applicable only in NS4
   var countupbgcolor=''
   var opentags='<font face="Verdana"><large>'
   var closetags='</large></font>'

   //////////DO NOT EDIT PASS THIS LINE//////////////////

   var montharray=new    
   Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
   var crosscount=''

   function start_countup(){
   if (document.layers)
   document.countupnsmain.visibility="show"
   else if (document.all||document.getElementById)
   crosscount=document.getElementById&&!document.all?   
   document.getElementById("countupie") : countupie
   countup()
   }

   if (document.all||document.getElementById)
   document.write('<span id="countupie" style="width:'+countupwidth+'; background-    
   color:'+countupbgcolor+'"></span>')

   window.onload=start_countup


   function countup(){
   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
   paststring=montharray[mo-1]+" "+da+", "+yr
   paststring="10:00"+montharray[mo-1]+" "+da+", "+yr
   dd=Date.parse(todaystring)-Date.parse(paststring)
   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 (document.layers){
   document.countupnsmain.document.countupnssub.document.write(opentags+dday+ " days    
   "+displaymessage+closetags)//to get more detail, enter one of the following in  the   
   write line(also in the else): +dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds    
   "
   document.countupnsmain.document.countupnssub.document.close()
   }
   else if (document.all||document.getElementById)
   crosscount.innerHTML=opentags+dday+ " days "+displaymessage+closetags//+dhour+"  
   hours, "+dmin+" minutes, and "+dsec+" seconds "

   setTimeout("countup()",1000)
   }
   </script>

Now, each cell row has a counter for a different event. I seem to be incapable of just putting this code in each , as it creates a conflict (i think)

I am completely new at this, and i have to get this sorted out. Can anybody help me out, or point me in the right direction please?

Thank you in advance

Was it helpful?

Solution

I spent a good amount of time trying to get the code you posted to work, and I have to say, that's some really bad code. There's a lot of unneeded code like:

paststring=montharray[mo-1]+" "+da+", "+yr
paststring="10:00"+montharray[mo-1]+" "+da+", "+yr

and a lot of just general formatting craziness. I believe I'd made it work and it's significantly easier to read than it was. This fiddle should help you make yours work.

http://jsfiddle.net/9DNaD/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top