Getting 2 scripts to run on the same webpage

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

    Getting 2 scripts to run on the same webpage

    I have 2 scipts that I am trying to get to run on the same page. One
    is a time/date script, the other is a countdown script (i.e. countdown
    days, hours, mins until a given date). They both work independent of
    each other, however, when both are on the page, the "active clock"
    does not work. I am assuming it is because some of the variables are
    the same???

    Can anyone help please?!?!
    Here are the 2 scripts:
    **Active Clock that displays current time/date info**
    <!-- Begin
    var dayarray=new Array("Sunday", "Monday","Tuesd ay","Wednesday" ,"Thursday","Fr iday","Saturday ")
    var montharray=new Array("January" ,"February","Ma rch","April","M ay","June","Jul y","August","Se ptember","Octob er","November", "December")
    function getthedate(){
    var mydate=new Date()
    var year=mydate.get Year()
    if (year < 1000)
    year+=1900
    var day=mydate.getD ay()
    var month=mydate.ge tMonth()
    var daym=mydate.get Date()
    if (daym<10)
    daym="0"+daym
    var hours=mydate.ge tHours()
    var minutes=mydate. getMinutes()
    var seconds=mydate. getSeconds()
    var dn="AM"
    if (hours>=12)
    dn="PM"
    if (hours>12){
    hours=hours-12
    }
    {
    d = new Date();
    Time24H = new Date();
    Time24H.setTime (d.getTime() + (d.getTimezoneO ffset()*60000) +
    3600000);
    InternetTime = Math.round((Tim e24H.getHours() *60+Time24H.get Minutes())
    / 1.44);
    if (InternetTime < 10) InternetTime = '00'+InternetTi me;
    else if (InternetTime < 100) InternetTime = '0'+InternetTim e;
    }
    if (hours==0)
    hours=12
    if (minutes<=9)
    minutes="0"+min utes
    if (seconds<=9)
    seconds="0"+sec onds
    //change font size here
    var cdate=dayarray[day]+", "+montharra y[month]+" "+daym+" "+year+" |
    "+hours+":"+min utes+" "+dn+" "
    if (document.all)
    document.all.cl ock.innerHTML=c date
    else if (document.getEl ementById)
    document.getEle mentById("clock ").innerHTML=cd ate
    else
    document.write( cdate)
    }
    if (!document.all& &!document.getE lementById)
    getthedate()
    function goforit(){
    if (document.all|| document.getEle mentById)
    setInterval("ge tthedate()",100 0)
    }
    window.onload=g oforit

    // End -->


    And the 2nd script - ****Countdown until given date*****
    function setcountdown(th eyear,themonth, theday){
    yr=theyear;mo=t hemonth;da=thed ay
    }

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

    //STEP 1: Configure the countdown-to date, in the format year, month,
    day:
    setcountdown(20 04,12,25)

    //STEP 2: Change the two text below to reflect the occasion, and
    message to display on that occasion, respectively
    var occasion="Chris tmas!"
    var message_on_occa sion="Merry Christmas!"

    //STEP 3: Configure the below 5 variables to set the width, height,
    background color, and text style of the countdown area
    var countdownwidth= '480px'
    var countdownheight ='20px'
    var countdownbgcolo r='white'
    var opentags='<font face="Arial" size="4" color="red"><sm all>'
    var closetags='</small></font>'

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

    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( '<span id="countdownie "
    style="width:'+ countdownwidth+ ';
    background-color:'+countdo wnbgcolor+'"></span>')

    window.onload=s tart_countdown


    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
    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 on day of occasion
    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
    }
    //if passed day of occasion
    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+ "Occasion already passed! "+closetags
    return
    }
    //else, if not yet
    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+" seconds left
    until "+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+" seconds left until "+occasion+clos etags
    }
    setTimeout("cou ntdown()",1000)
    }
  • McKirahan

    #2
    Re: Getting 2 scripts to run on the same webpage

    "Mary Catherine" <MaryCatherine0 0@gmail.com> wrote in message
    news:5899c237.0 411110842.6e1e1 908@posting.goo gle.com...[color=blue]
    > I have 2 scipts that I am trying to get to run on the same page. One
    > is a time/date script, the other is a countdown script (i.e. countdown
    > days, hours, mins until a given date). They both work independent of
    > each other, however, when both are on the page, the "active clock"
    > does not work. I am assuming it is because some of the variables are
    > the same???[/color]

    [snip]

    "montharray " is declared twice.

    var montharray=new
    Array("January" ,"February","Ma rch","April","M ay","June","Jul y","August","Se p
    tember","Octobe r","November"," December")

    var montharray=new
    Array("Jan","Fe b","Mar","Apr", "May","Jun","Ju l","Aug","Sep", "Oct","Nov","De c
    ")


    Comment

    • Dr John Stockton

      #3
      Re: Getting 2 scripts to run on the same webpage

      JRS: In article <hPMkd.86544$R0 5.20332@attbi_s 53>, dated Thu, 11 Nov
      2004 16:54:37, seen in news:comp.lang. javascript, McKirahan
      <News@McKirahan .com> posted :[color=blue]
      >"Mary Catherine" <MaryCatherine0 0@gmail.com> wrote in message
      >news:5899c237. 0411110842.6e1e 1908@posting.go ogle.com...[color=green]
      >> I have 2 scipts that I am trying to get to run on the same page. One
      >> is a time/date script, the other is a countdown script (i.e. countdown
      >> days, hours, mins until a given date). They both work independent of
      >> each other, however, when both are on the page, the "active clock"
      >> does not work. I am assuming it is because some of the variables are
      >> the same???[/color]
      >
      >[snip]
      >
      >"montharray " is declared twice.
      >
      >var montharray=new
      >Array("January ","February","M arch","April"," May","June","Ju ly","August","S ep
      >tember","Octob er","November", "December")
      >
      >var montharray=new
      >Array("Jan","F eb","Mar","Apr" ,"May","Jun","J ul","Aug","Sep" ,"Oct","Nov","D ec
      >")[/color]

      That's undesirable, but does no harm.

      The OP's code is not indented for structure, and therefore not worth
      reading in full. However :-

      For a clock, setTimeout(..., 1000) is unsuitable; see
      <URL:http://www.merlyn.demo n.co.uk/js-date0.htm#TaI>

      var year=mydate.get Year() ; if (year < 1000) year+=1900
      will fail on browsers which give the sequence 97,98,99,00,01 ; such
      were said to exist. Use getFullYear or a substitute :
      <URL:http://www.merlyn.demo n.co.uk/js-date0.htm#gFY>, getFY() .

      InternetTime appears to be an estimate of Central European Standard
      Time; but it seems not to be used.

      The countdown will not allow for Summer Time transitions; users will
      expect an integer number of days between 25 Jun 0000h and 25 Dec 0000h.

      The programmer should have modularised the code, Leading Zero being an
      example.

      --
      © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
      <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of 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

      • Michael Winter

        #4
        Re: Getting 2 scripts to run on the same webpage

        On 11 Nov 2004 08:42:53 -0800, Mary Catherine <MaryCatherine0 0@gmail.com>
        wrote:
        [color=blue]
        > I have 2 scipts that I am trying to get to run on the same page. One is
        > a time/date script, the other is a countdown script (i.e. countdown
        > days, hours, mins until a given date). They both work independent of
        > each other, however, when both are on the page, the "active clock" does
        > not work. I am assuming it is because some of the variables are the
        > same???[/color]

        Whilst some identifiers do clash, I doubt that has much of an impact. The
        biggest problem is that both try to assign a function to the document's
        load event handler, resulting in the second block of code replacing the
        first's starting function.
        [color=blue]
        > Can anyone help please?!?![/color]

        Certainly. The first thing is to bin the scripts you presented. I
        apologise if you authored them, but they are badly written (the fact
        you've had problems proves that), bloated, and inefficient.

        I've written replacements, but as the second block of code wouldn't
        execute (perhaps you didn't post part of it), I've had to guess at what it
        did. The same is true, to an extent with the first: I was unable to see
        what the author was trying to achieve with the getTimezoneOffs et part of
        the script, so I ignored that. If they don't produce what you expected,
        please describe in detail what should occur.

        A demo can be found at
        <URL:http://www.mlwinter.pw p.blueyonder.co .uk/clj/catherine/time.html>. It
        will be deleted in about a week. There are three script files; two for the
        functions, and a third which contains some library code of mine.

        There is an important caveat to using this code[1], with the events code
        in particular. If you need to add code to be fired when the page loads, do
        *not* write

        <body ... onload="...">

        The code I've presented will be interferred with, and it will stop
        working. Instead, write

        dom.events.addE ventListener(th is, 'load', function() {
        /* Your code here. */
        });

        in a script block.

        Similarly, don't write

        window.onload = funcName;

        Use

        dom.events.addE ventListener(th is, 'load', funcName);

        instead. This might mean you need to change other scripts.

        The reason, if you're interested, is that the events library code creates
        a function, a dispatcher, which is added as an event listener. When you
        add your own event listeners, the dispatcher adds it to an internal list
        and, when the event is fired, it calls all of the functions in this list.
        This allows you to add multiple event listeners to the same element[2].

        Please be aware that I classify the library code as a beta version: you
        may find bugs. If you read this post Dr Stockton, I'd be interested to
        know if IE4 runs the demo properly.

        [snipped code]

        If you post here again with more code, could I make a request? Please
        either manually wrap the code to about 70 characters wide, or place a
        demonstration online and link to it (preferred). There were numerous
        syntax errors where your newsreader automatically wrapped the code. String
        literals split across lines, single line comments on two lines, etc. This
        makes a debugging effort harder.

        Hope that helps,
        Mike


        [1] Aside from the obvious one: don't pretend you wrote it. :)
        [2] The W3C DOM provides this functionality too, which is used if
        available, but browsers like IE need this emulation.

        --
        Michael Winter
        Replace ".invalid" with ".uk" to reply by e-mail.

        Comment

        • Mary Catherine

          #5
          Re: Getting 2 scripts to run on the same webpage

          Dr John Stockton <spam@merlyn.de mon.co.uk> wrote in message news:<u1lnBbBvI 8kBFwZW@merlyn. demon.co.uk>...[color=blue]
          > JRS: In article <hPMkd.86544$R0 5.20332@attbi_s 53>, dated Thu, 11 Nov
          > 2004 16:54:37, seen in news:comp.lang. javascript, McKirahan
          > <News@McKirahan .com> posted :[color=green]
          > >"Mary Catherine" <MaryCatherine0 0@gmail.com> wrote in message
          > >news:5899c237. 0411110842.6e1e 1908@posting.go ogle.com...[color=darkred]
          > >> I have 2 scipts that I am trying to get to run on the same page. One
          > >> is a time/date script, the other is a countdown script (i.e. countdown
          > >> days, hours, mins until a given date). They both work independent of
          > >> each other, however, when both are on the page, the "active clock"
          > >> does not work. I am assuming it is because some of the variables are
          > >> the same???[/color]
          > >
          > >[snip]
          > >
          > >"montharray " is declared twice.
          > >
          > >var montharray=new
          > >Array("January ","February","M arch","April"," May","June","Ju ly","August","S ep
          > >tember","Octob er","November", "December")
          > >
          > >var montharray=new
          > >Array("Jan","F eb","Mar","Apr" ,"May","Jun","J ul","Aug","Sep" ,"Oct","Nov","D ec
          > >")[/color]
          >
          > That's undesirable, but does no harm.
          >
          > The OP's code is not indented for structure, and therefore not worth
          > reading in full. However :-
          >
          > For a clock, setTimeout(..., 1000) is unsuitable; see
          > <URL:http://www.merlyn.demo n.co.uk/js-date0.htm#TaI>
          >
          > var year=mydate.get Year() ; if (year < 1000) year+=1900
          > will fail on browsers which give the sequence 97,98,99,00,01 ; such
          > were said to exist. Use getFullYear or a substitute :
          > <URL:http://www.merlyn.demo n.co.uk/js-date0.htm#gFY>, getFY() .
          >
          > InternetTime appears to be an estimate of Central European Standard
          > Time; but it seems not to be used.
          >
          > The countdown will not allow for Summer Time transitions; users will
          > expect an integer number of days between 25 Jun 0000h and 25 Dec 0000h.
          >
          > The programmer should have modularised the code, Leading Zero being an
          > example.[/color]

          *************** ********
          I will take a look at your suggestions and see if that works. Thanks!
          MC

          Comment

          • Dr John Stockton

            #6
            Re: Getting 2 scripts to run on the same webpage

            JRS: In article <opshckp2nqx13k vk@atlantis>, dated Fri, 12 Nov 2004
            10:27:03, seen in news:comp.lang. javascript, Michael Winter <M.Winter@bl
            ueyonder.co.inv alid> posted :
            [color=blue]
            >A demo can be found at
            ><URL:http://www.mlwinter.pw p.blueyonder.co .uk/clj/catherine/time.html>. It
            >will be deleted in about a week. There are three script files; two for the
            >functions, and a third which contains some library code of mine.[/color]
            [color=blue]
            > ...[/color]
            [color=blue]
            >Please be aware that I classify the library code as a beta version: you
            >may find bugs. If you read this post Dr Stockton, I'd be interested to
            >know if IE4 runs the demo properly.[/color]

            I've not worked out exactly what it should do.

            It displays, in my IE4 :

            If you want to style the text below, use CSS. You can use the id
            attribute values as selectors.

            Friday, 12 November 2004 23:46
            There are approximately 41 days, 0 hours, and 13 minutes until
            Christmas

            then twice gives a script error message box, approximately :

            Line: 1
            Char: 1
            Error: Object expected
            Code: 0

            Suggestion : the countdown, for demo purposes, should show seconds;
            otherwise it takes a long time to tell that nothing happens.




            From reading the thread, I suspect that an adapted subset of <URL:http:
            //www.merlyn.demo n.co.uk/js-date2.htm#RC> would do what is wanted;
            /inter alia/, it shows a running DoW YYYY-MM-DD hh:mm:ss local clock
            and a countdown in Days + hh:mm:ss to the nearest Christmas noon
            (i.e., IIRC, at Christmas noon each year it jumps 365/6 days).

            By using new Date(+N) at least part of the code is made valid for
            the years -68 to +99, or so my comment implies. Admittedly, Christmas
            is not applicable in negative years; and no future Christmas is numbered
            less than 2004.

            Note that the page uses one setTimeout for both YMDhms clock and
            countdown, and another for JDN & suchlike.

            --
            © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
            <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of 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

            • Michael Winter

              #7
              Re: Getting 2 scripts to run on the same webpage

              On Sat, 13 Nov 2004 16:08:23 +0000, Dr John Stockton
              <spam@merlyn.de mon.co.uk> wrote:

              [snip]
              [color=blue]
              > I've not worked out exactly what it should do.[/color]

              Sorry. The "first" line should display the current time. The "second"
              should display a countdown, currently set to 2004-12-25 00:00 (though it
              would have been the 24th when you saw it).

              Just to note, the reason for the lack of synchronisation between the two
              outputs is that they are calculated separately, rather than being linked
              to the same Date object. They could be combined, but should one need to be
              separated from the other, it would burden the user.
              [color=blue]
              > It displays, in my IE4 :
              >
              > If you want to style the text below, use CSS. You can use
              > the id attribute values as selectors.
              >
              > Friday, 12 November 2004 23:46
              > There are approximately 41 days, 0 hours, and 13 minutes
              > until Christmas[/color]

              That's promising...
              [color=blue]
              > then twice gives a script error message box, approximately :
              >
              > Line: 1
              > Char: 1
              > Error: Object expected
              > Code: 0[/color]

              ....but that's confusing. I was worried that IE4 might object to something,
              probably due to the type of patterns used. The result I was expecting was
              either no problems at all, or total failure. Seems to be neither. Of
              course, Microsoft's infamous script debugging messages don't really help
              narrow down the cause.

              The other cause of concern was the library code used, including a modified
              version of DynWrite (dom.write), has never been used in IE4 as far as I
              know.
              [color=blue]
              > Suggestion : the countdown, for demo purposes, should show seconds;
              > otherwise it takes a long time to tell that nothing happens.[/color]

              True. I had that when I was testing the code, but removed it before
              uploading. I've restored it. I also added links to the scripts (though
              that may not be useful with IE).
              [color=blue]
              > From reading the thread, I suspect that an adapted subset of
              > <URL:http://www.merlyn.demo n.co.uk/js-date2.htm#RC> would do what is
              > wanted;[/color]

              That's what's effectively happened. As an afterthought, I decided to look
              at your site, particularly as you corrected me on a related matter in the
              past. The code is comparable, with the only part of note that's missing is

              D += (N.getTimezoneO ffset()-X.getTimezoneOf fset())*60000 // ST

              from the function, ReptNow. To be honest, I don't see the point in it.
              Surely the timezone in both Date objects will be identical, so you'll
              always add zero. I must be missing something.

              [snip]
              [color=blue]
              > (i.e., IIRC, at Christmas noon each year it jumps 365/6 days).[/color]

              That's what I see from reading the code.

              [snip]

              Thank you for looking,
              Mike

              --
              Michael Winter
              Replace ".invalid" with ".uk" to reply by e-mail.

              Comment

              • Dr John Stockton

                #8
                Re: Getting 2 scripts to run on the same webpage

                JRS: In article <opshey5aaax13k vk@atlantis>, dated Sat, 13 Nov 2004
                17:32:39, seen in news:comp.lang. javascript, Michael Winter <M.Winter@bl
                ueyonder.co.inv alid> posted :
                [color=blue]
                > As an afterthought, I decided to look
                >at your site, particularly as you corrected me on a related matter in the
                >past. The code is comparable, with the only part of note that's missing is
                >
                > D += (N.getTimezoneO ffset()-X.getTimezoneOf fset())*60000 // ST
                >
                > from the function, ReptNow. To be honest, I don't see the point in it.
                >Surely the timezone in both Date objects will be identical, so you'll
                >always add zero. I must be missing something.[/color]

                Comment ST. N is today, and X is Christmas. In Summer Time, D is a
                one-hour adjustment. That's for civil days displayed.

                [color=blue][color=green]
                >> (i.e., IIRC, at Christmas noon each year it jumps 365/6 days).[/color]
                >
                >That's what I see from reading the code.[/color]

                Good. I don't recall whether I ever watched it happen. But on second
                thoughts, it should change at 00:00 on the 25th, because of variable Z.


                By the way, I control NewPix with Limits to be SURE that the page cannot
                ever continuously fetch images from the server. If it can be confirmed
                that GetFigs() actually fetches the ten GIFs, and NewPix() does not
                cause Web access, I can remove Limits.

                --
                © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of 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

                • Michael Winter

                  #9
                  Re: Getting 2 scripts to run on the same webpage

                  On Sun, 14 Nov 2004 14:01:13 +0000, Dr John Stockton
                  <spam@merlyn.de mon.co.uk> wrote:
                  [color=blue]
                  > JRS: In article <opshey5aaax13k vk@atlantis>, dated Sat, 13 Nov 2004
                  > 17:32:39, seen in news:comp.lang. javascript, Michael Winter
                  > <M.Winter@bluey onder.co.invali d> posted :[/color]

                  [snip]
                  [color=blue][color=green]
                  >> D += (N.getTimezoneO ffset()-X.getTimezoneOf fset())*60000 // ST[/color][/color]

                  [snip]
                  [color=blue]
                  > In Summer Time, D is a one-hour adjustment. [...][/color]

                  Of course!
                  [color=blue][color=green][color=darkred]
                  >>> (i.e., IIRC, at Christmas noon each year it jumps 365/6 days).[/color]
                  >>
                  >> That's what I see from reading the code.[/color]
                  >
                  > Good. I don't recall whether I ever watched it happen. But on second
                  > thoughts, it should change at 00:00 on the 25th, because of variable Z.[/color]

                  I suppose it depends on your aims. In the OP's case, the target date
                  requires a special case message. At present my code should display the
                  message for exactly twenty-four hours (must admit I haven't actually
                  tested that, though). After that, nothing is displayed, but it could be
                  changed to start the countdown again.
                  [color=blue]
                  > By the way, I control NewPix with Limits to be SURE that the page cannot
                  > ever continuously fetch images from the server.[/color]

                  I don't think you could ever guarantee that. If the user agent doesn't
                  cache the images due to browser settings, they will be retrieved
                  constantly.

                  Mike

                  --
                  Michael Winter
                  Replace ".invalid" with ".uk" to reply by e-mail.

                  Comment

                  • Mary Catherine

                    #10
                    Re: Getting 2 scripts to run on the same webpage

                    "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message news:<opshckp2n qx13kvk@atlanti s>...[color=blue]
                    > On 11 Nov 2004 08:42:53 -0800, Mary Catherine <MaryCatherine0 0@gmail.com>
                    > wrote:
                    >[color=green]
                    > > I have 2 scipts that I am trying to get to run on the same page. One is
                    > > a time/date script, the other is a countdown script (i.e. countdown
                    > > days, hours, mins until a given date). They both work independent of
                    > > each other, however, when both are on the page, the "active clock" does
                    > > not work. I am assuming it is because some of the variables are the
                    > > same???[/color]
                    >
                    > Whilst some identifiers do clash, I doubt that has much of an impact. The
                    > biggest problem is that both try to assign a function to the document's
                    > load event handler, resulting in the second block of code replacing the
                    > first's starting function.
                    >[color=green]
                    > > Can anyone help please?!?![/color]
                    >
                    > Certainly. The first thing is to bin the scripts you presented. I
                    > apologise if you authored them, but they are badly written (the fact
                    > you've had problems proves that), bloated, and inefficient.
                    >
                    > I've written replacements, but as the second block of code wouldn't
                    > execute (perhaps you didn't post part of it), I've had to guess at what it
                    > did. The same is true, to an extent with the first: I was unable to see
                    > what the author was trying to achieve with the getTimezoneOffs et part of
                    > the script, so I ignored that. If they don't produce what you expected,
                    > please describe in detail what should occur.
                    >
                    > A demo can be found at
                    > <URL:http://www.mlwinter.pw p.blueyonder.co .uk/clj/catherine/time.html>. It
                    > will be deleted in about a week. There are three script files; two for the
                    > functions, and a third which contains some library code of mine.
                    >
                    > There is an important caveat to using this code[1], with the events code
                    > in particular. If you need to add code to be fired when the page loads, do
                    > *not* write
                    >
                    > <body ... onload="...">
                    >
                    > The code I've presented will be interferred with, and it will stop
                    > working. Instead, write
                    >
                    > dom.events.addE ventListener(th is, 'load', function() {
                    > /* Your code here. */
                    > });
                    >
                    > in a script block.
                    >
                    > Similarly, don't write
                    >
                    > window.onload = funcName;
                    >
                    > Use
                    >
                    > dom.events.addE ventListener(th is, 'load', funcName);
                    >
                    > instead. This might mean you need to change other scripts.
                    >
                    > The reason, if you're interested, is that the events library code creates
                    > a function, a dispatcher, which is added as an event listener. When you
                    > add your own event listeners, the dispatcher adds it to an internal list
                    > and, when the event is fired, it calls all of the functions in this list.
                    > This allows you to add multiple event listeners to the same element[2].
                    >
                    > Please be aware that I classify the library code as a beta version: you
                    > may find bugs. If you read this post Dr Stockton, I'd be interested to
                    > know if IE4 runs the demo properly.
                    >
                    > [snipped code]
                    >
                    > If you post here again with more code, could I make a request? Please
                    > either manually wrap the code to about 70 characters wide, or place a
                    > demonstration online and link to it (preferred). There were numerous
                    > syntax errors where your newsreader automatically wrapped the code. String
                    > literals split across lines, single line comments on two lines, etc. This
                    > makes a debugging effort harder.
                    >
                    > Hope that helps,
                    > Mike
                    >
                    >
                    > [1] Aside from the obvious one: don't pretend you wrote it. :)
                    > [2] The W3C DOM provides this functionality too, which is used if
                    > available, but browsers like IE need this emulation.[/color]

                    *************** *****
                    Thanks! Ive looked at the files you've linked for me. I did not write
                    these files, as js is something I am SLOWLY learning to do. They are,
                    rather, scripts the former web 'developer' either wrote or got
                    somewhere.

                    Thank you for the link you posted. I will save these and take a look
                    at
                    them tomorrow when I have more time for 'time wasting activities' as
                    Ive
                    been told they are called.

                    Thanks again everyone - even though 1/2 the conversation was way over
                    my little blonde head! Im sure with enough time and patience, I'll be
                    able
                    to figure out whats going on here!

                    Comment

                    • Michael Winter

                      #11
                      Re: Getting 2 scripts to run on the same webpage

                      On 15 Nov 2004 14:16:54 -0800, Mary Catherine <MaryCatherine0 0@gmail.com>
                      wrote:
                      [color=blue]
                      > "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
                      > news:<opshckp2n qx13kvk@atlanti s>...[/color]

                      [snip]
                      [color=blue][color=green]
                      >> The reason, if you're interested, is that the events library code
                      >> creates a function, a dispatcher, which is added as an event listener.
                      >> When you add your own event listeners, the dispatcher adds it to an
                      >> internal list and, when the event is fired, it calls all of the
                      >> functions in this list. This allows you to add multiple event listeners
                      >> to the same element.[/color][/color]

                      I forgot to add to the above: If you do add listeners using

                      window.onload = funcName;

                      the dispatcher will be overwritten and the listeners it manages, lost.

                      [snip]
                      [color=blue]
                      > Thank you for the link you posted. I will save these and take a look at
                      > them tomorrow when I have more time for 'time wasting activities' as Ive
                      > been told they are called.[/color]

                      There were a couple of mistakes which led to changes to all three script
                      files[1]. I also added to the countdown script compensation for daylight
                      savings time.
                      [color=blue]
                      > Thanks again everyone - even though 1/2 the conversation was way over my
                      > little blonde head! Im sure with enough time and patience, I'll be able
                      > to figure out whats going on here![/color]

                      Usenet is meant for discussion so if you have questions, you're more than
                      welcome to ask them.

                      Good luck,
                      Mike


                      [1] These changes might prevent the errors Dr Stockton reported in IE 4.

                      --
                      Michael Winter
                      Replace ".invalid" with ".uk" to reply by e-mail.

                      Comment

                      • Dr John Stockton

                        #12
                        Re: Getting 2 scripts to run on the same webpage

                        JRS: In article <opshjw2esix13k vk@atlantis>, dated Tue, 16 Nov 2004
                        09:35:58, seen in news:comp.lang. javascript, Michael Winter <M.Winter@bl
                        ueyonder.co.inv alid> posted :[color=blue]
                        >
                        >[1] These changes might prevent the errors Dr Stockton reported in IE 4.[/color]

                        They do; it shows date and changing time, and counts down to Christmas,
                        showing a time that agrees with mine.

                        If you keep it as a demo, ISTM worth noting what the CSS link does (I
                        was expecting a CSSified version of the demo), and remarking on what the
                        *.js links might do (my system is not set up to show them as text).

                        --
                        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
                        Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
                        PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
                        Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

                        Comment

                        • Michael Winter

                          #13
                          Re: Getting 2 scripts to run on the same webpage

                          On Tue, 16 Nov 2004 23:31:54 +0000, Dr John Stockton
                          <spam@merlyn.de mon.co.uk> wrote:
                          [color=blue]
                          > JRS: In article <opshjw2esix13k vk@atlantis>, dated Tue, 16 Nov 2004
                          > 09:35:58, seen in news:comp.lang. javascript, Michael Winter <M.Winter@bl
                          > ueyonder.co.inv alid> posted :
                          >[color=green]
                          >> [1] These changes might prevent the errors Dr Stockton reported in IE 4.[/color]
                          >
                          > They do; it shows date and changing time, and counts down to Christmas,
                          > showing a time that agrees with mine.[/color]

                          It was a mistake similar to one I've made previously.

                          The functions called by setTimeout are inner functions. This doesn't cause
                          any problems with function-version of the method, but IE 4 only takes a
                          string argument.

                          The error was that the resulting string would evaluate to the inner
                          function name, but as that isn't available at global scope (the context in
                          which the string is evaluated), IE throws an error. The solution was to
                          generate a name that was unique at global scope, and assign a reference to
                          the inner function there.
                          [color=blue]
                          > If you keep it as a demo, [...][/color]

                          I did intend to delete it once I was satified the OP didn't need it.

                          Mike

                          --
                          Michael Winter
                          Replace ".invalid" with ".uk" to reply by e-mail.

                          Comment

                          Working...