Help

A

adam

<SCRIPT language=JavaScript1.2>

function setcountdown(theyear,themonth,theday,thehour,themin,thesec){
yr=theyear;mo=themonth;da=theday;hr=thehour;min=themin;sec=thesec
}
// modify the following lines to change the appearance of your timer
var occasion=""
var message_on_occasion="Auction Closed"
var countdownwidth='220px'
var countdownheight='35px'
var countdownbgcolor='aabbcc'
var opentags='<font face="Verdana"><small>'
var closetags='</small></font>'
// don't change anything from here !!
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var crosscount=''
function start_countdown(){
if (document.layers)
document.countdownnsmain.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countdownie")
: countdownie
countdown()
}
if (document.all||document.getElementById)
document.write('<center><span id="countdownie"
style="width:'+countdownwidth+';
background-color:'+countdownbgcolor+'"></span></center>')
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]+" "+todayd+", "+todayy+"
"+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[mo-1]+" "+da+", "+yr+" "+hr+":"+min+":"+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(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
}
else if (dday<=-1){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+"Occasion
already passed! "+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+"Auction already ended ! "+closetags
return
}
else{
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+dday+
" days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" secs
"+occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+dday+ " days, "+dhour+" hours, "+dmin+"
minutes, and "+dsec+" secs "+occasion+closetags
}
setTimeout("countdown()",1000)
}
//-->
</SCRIPT>

<SCRIPT language=JavaScript>

setcountdown(2004,02,17,16,45,00)

</SCRIPT>
 
M

Michael Winter

It's usually worth saying what you need help with. A more descriptive
subject line is a good idea, too.
<SCRIPT language=JavaScript1.2>

I don't think you want to do that: most people have no idea what the
consequences are. In any case, the language attribute is deprecated in
favour of the required type attribute. Replace this SCRIPT element, and
the one below, with this:

<script type="text/javascript">

In virtually all of the statements below, you neglect to include a
terminating semi-colon (;). This is bad practice and should be avoided.
function setcountdown(theyear,themonth,theday,thehour,themin,thesec){
yr=theyear;mo=themonth;da=theday;hr=thehour;min=themin;sec=thesec
}
// modify the following lines to change the appearance of your timer
var occasion=""
var message_on_occasion="Auction Closed"
var countdownwidth='220px'
var countdownheight='35px'
var countdownbgcolor='aabbcc'
var opentags='<font face="Verdana"><small>'
var closetags='</small></font>'

When placing a script inside a HTML document, you should always escape the
slash in end tags:

var closetags = '<\/small><\/font>';

This prevents browsers from closing the SCRIPT element early.

[snip]
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+dday+ " days, "+dhour+" hours, "+dmin+"
minutes, and "+dsec+" secs "+occasion+closetags
}

There are other examples, but this is the clearest...

Generally when feature testing, you actually test methods and properties
that one is about to use. Exactly what bearing does support for
document.all[] or document.getElementById() have on Element.innerHTML? A
much more sensible test would be:

if( 'undefined' != typeof Element.innerHTML )

where Element would be crosscount, in this case.
setTimeout("countdown()",1000)
}
//-->

Why this is present, I have no idea. Even so, script hiding through SGML
comments is a practice that should be abandoned.

[snip]

Please post sensibly in future.

Mike
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen
in news:comp.lang.javascript said:
function setcountdown(theyear,themonth,theday,thehour,themin,thesec){
yr=theyear;mo=themonth;da=theday;hr=thehour;min=themin;sec=thesec
}

Code should be indented, and blank lines added, to show structure.

Code in News should be written within a right margin of about 72
characters, and not allowed to be wrapped by news software. You cannot
expect readers to want to fix the errors you have introduced by
carelessness in news-posting before starting on those in the code you
have.

Read the FAQ, absorb its lessons, and re-post with an actual question.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top