Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coding help needed

Status
Not open for further replies.

blekfis

Programmer
Oct 19, 2001
38
SE
I'd like to use the script below, but I want to use the servertime instead of the computers local time.... Anyone who can help me?

/N!cklas


----------------------------------------------------


<script language=&quot;JavaScript1.2&quot;>


function setcountdown(theyear,themonth,theday,thehour,themin,thesec){
yr=theyear;mo=themonth;da=theday;hr=thehour;min=themin;sec=thesec
}

//////////CONFIGURE THE COUNTDOWN SCRIPT HERE//////////////////

//STEP 1: Configure the countdown-to date, in the format year, month, day, hour(0=midnight,23=11pm), minutes, seconds:
setcountdown(2003,01,08,00,00,00)

//STEP 2: Change the two text below to reflect the occasion, and message to display on that occasion, respectively
var occasion=&quot;<br>Snart tävling...&quot;
var message_on_occasion=&quot;<b>Tävlingen är igång!</b>&quot;

//STEP 3: Configure the below 5 variables to set the width, height, background color, and text style of the countdown area
var countdownwidth='140px'
var countdownheight='140px'
var countdownbgcolor=''
var opentags='<font face=&quot;Verdana&quot;><small>'
var closetags='</small></font>'

//////////DO NOT EDIT PAST THIS LINE//////////////////

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

function start_countdown(){
if (document.layers)
document.countdownnsmain.visibility=&quot;show&quot;
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById(&quot;countdownie&quot;) : countdownie
countdown()
}

if (document.all||document.getElementById)
document.write('<span id=&quot;countdownie&quot; style=&quot;width:'+countdownwidth+'; background-color:'+countdownbgcolor+'&quot;></span>')

window.onload=start_countdown


function countdown(){
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]+&quot; &quot;+todayd+&quot;, &quot;+todayy+&quot; &quot;+todayh+&quot;:&quot;+todaymin+&quot;:&quot;+todaysec
futurestring=montharray[mo-1]+&quot; &quot;+da+&quot;, &quot;+yr+&quot; &quot;+hr+&quot;:&quot;+min+&quot;:&quot;+sec
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 on day of occasion
if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=1&&todayd==da){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+message_on_occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+message_on_occasion+closetags
return
}
//if passed day of occasion
else if (dday<=-1){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+&quot;Occasion already passed! &quot;+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+&quot;Occasion already passed! &quot;+closetags
return
}
//else, if not yet
else{
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+dday+ &quot;D &quot;+dhour+&quot;T &quot;+dmin+&quot;M &quot;+dsec+&quot;S &quot;+occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+dday+ &quot;D &quot;+dhour+&quot;H &quot;+dmin+&quot;M &quot;+dsec+&quot;S &quot;+occasion+closetags
}
setTimeout(&quot;countdown()&quot;,1000)
}
</script>
<ilayer id=&quot;countdownnsmain&quot; width=&{countdownwidth}; height=&{countdownheight}; bgColor=&{countdownbgcolor}; visibility=hide><layer id=&quot;countdownnssub&quot; width=&{countdownwidth}; height=&{countdownheight}; left=0 top=0></layer></ilayer>
 
in order to get the server time you will need to incorpurate some server side scripting in it. at that point all you need to due is declare the var with the value
ASP example
var myDate = &quot;<%now%>&quot; ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top