Help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • adam

    Help

    <SCRIPT language=JavaSc ript1.2>

    function setcountdown(th eyear,themonth, theday,thehour, themin,thesec){
    yr=theyear;mo=t hemonth;da=thed ay;hr=thehour;m in=themin;sec=t hesec
    }
    // modify the following lines to change the appearance of your timer
    var occasion=""
    var message_on_occa sion="Auction Closed"
    var countdownwidth= '220px'
    var countdownheight ='35px'
    var countdownbgcolo r='aabbcc'
    var opentags='<font face="Verdana"> <small>'
    var closetags='</small></font>'
    // don't change anything from here !!
    var montharray=new Array("Jan","Fe b","Mar","Apr", "May","Jun","Ju l","Aug","Sep", "Oct","Nov","De c")
    var crosscount=''
    function start_countdown (){
    if (document.layer s)
    document.countd ownnsmain.visib ility="show"
    else if (document.all|| document.getEle mentById)
    crosscount=docu ment.getElement ById&&!document .all?document.g etElementById(" countdownie")
    : countdownie
    countdown()
    }
    if (document.all|| document.getEle mentById)
    document.write( '<center><span id="countdownie "
    style="width:'+ countdownwidth+ ';
    background-color:'+countdo wnbgcolor+'"></span></center>')
    function countdown(){
    var today=new Date()
    var todayy=today.ge tYear()
    if (todayy < 1000)
    todayy+=1900
    var todaym=today.ge tMonth()
    var todayd=today.ge tDate()
    var todayh=today.ge tHours()
    var todaymin=today. getMinutes()
    var todaysec=today. getSeconds()
    var todaystring=mon tharray[todaym]+" "+todayd+", "+todayy+"
    "+todayh+":"+to daymin+":"+toda ysec
    futurestring=mo ntharray[mo-1]+" "+da+", "+yr+" "+hr+":"+min+": "+sec
    dd=Date.parse(f uturestring)-Date.parse(toda ystring)
    dday=Math.floor (dd/(60*60*1000*24) *1)
    dhour=Math.floo r((dd%(60*60*10 00*24))/(60*60*1000)*1)
    dmin=Math.floor (((dd%(60*60*10 00*24))%(60*60* 1000))/(60*1000)*1)
    dsec=Math.floor ((((dd%(60*60*1 000*24))%(60*60 *1000))%(60*100 0))/1000*1)
    if(dday<=0&&dho ur<=0&&dmin<=0& &dsec<=1&&today d==da){
    if (document.layer s){
    document.countd ownnsmain.docum ent.countdownns sub.document.wr ite(opentags+me ssage_on_occasi on+closetags)
    document.countd ownnsmain.docum ent.countdownns sub.document.cl ose()
    }
    else if (document.all|| document.getEle mentById)
    crosscount.inne rHTML=opentags+ message_on_occa sion+closetags
    return
    }
    else if (dday<=-1){
    if (document.layer s){
    document.countd ownnsmain.docum ent.countdownns sub.document.wr ite(opentags+"O ccasion
    already passed! "+closetags )
    document.countd ownnsmain.docum ent.countdownns sub.document.cl ose()
    }
    else if (document.all|| document.getEle mentById)
    crosscount.inne rHTML=opentags+ "Auction already ended ! "+closetags
    return
    }
    else{
    if (document.layer s){
    document.countd ownnsmain.docum ent.countdownns sub.document.wr ite(opentags+dd ay+
    " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" secs
    "+occasion+clos etags)
    document.countd ownnsmain.docum ent.countdownns sub.document.cl ose()
    }
    else if (document.all|| document.getEle mentById)
    crosscount.inne rHTML=opentags+ dday+ " days, "+dhour+" hours, "+dmin+"
    minutes, and "+dsec+" secs "+occasion+clos etags
    }
    setTimeout("cou ntdown()",1000)
    }
    //-->
    </SCRIPT>

    <SCRIPT language=JavaSc ript>

    setcountdown(20 04,02,17,16,45, 00)

    </SCRIPT>
  • Michael Winter

    #2
    Re: Help

    On 16 Feb 2004 11:09:14 -0800, adam <adamnichols45@ hotmail.com> wrote:

    It's usually worth saying what you need help with. A more descriptive
    subject line is a good idea, too.
    [color=blue]
    > <SCRIPT language=JavaSc ript1.2>[/color]

    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.
    [color=blue]
    > function setcountdown(th eyear,themonth, theday,thehour, themin,thesec){
    > yr=theyear;mo=t hemonth;da=thed ay;hr=thehour;m in=themin;sec=t hesec
    > }
    > // modify the following lines to change the appearance of your timer
    > var occasion=""
    > var message_on_occa sion="Auction Closed"
    > var countdownwidth= '220px'
    > var countdownheight ='35px'
    > var countdownbgcolo r='aabbcc'
    > var opentags='<font face="Verdana"> <small>'
    > var closetags='</small></font>'[/color]

    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]
    [color=blue]
    > else if (document.all|| document.getEle mentById)
    > crosscount.inne rHTML=opentags+ dday+ " days, "+dhour+" hours, "+dmin+"
    > minutes, and "+dsec+" secs "+occasion+clos etags
    > }[/color]

    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.getEle mentById() have on Element.innerHT ML? A
    much more sensible test would be:

    if( 'undefined' != typeof Element.innerHT ML )

    where Element would be crosscount, in this case.
    [color=blue]
    > setTimeout("cou ntdown()",1000)
    > }
    > //-->[/color]

    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

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    • Hywel Jenkins

      #3
      Re: Help

      In article <5388ff.0402161 109.65ec6331@po sting.google.co m>,
      adamnichols45@h otmail.com says...[color=blue]
      > <SCRIPT language=JavaSc ript1.2>[/color]

      Nice one. A complete mis-use of the subject line; loads of code; no
      description of your problem. Really smart.

      --
      Hywel I do not eat quiche


      Comment

      • Dr John Stockton

        #4
        Re: Help

        JRS: In article <5388ff.0402161 109.65ec6331@po sting.google.co m>, seen
        in news:comp.lang. javascript, adam <adamnichols45@ hotmail.com> posted at
        Mon, 16 Feb 2004 11:09:14 :-[color=blue]
        >
        >function setcountdown(th eyear,themonth, theday,thehour, themin,thesec){
        >yr=theyear;mo= themonth;da=the day;hr=thehour; min=themin;sec= thesec
        >}[/color]

        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.

        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
        <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
        <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

        Comment

        Working...