renaming a .js file ????

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

    #1

    renaming a .js file ????

    I have a javascript quiz webpage... that loads the questions and answers
    from a .js file...

    at this time i use the following to call the data

    <script src="quiz_a.js" ></script>

    this works fine, but I'd like a new lot of data to be used each day...

    i have the javascript code to number each day of the year from 1 to 356 (or
    days in the year)

    what i would like to do is find some way to rename the .js file that is
    called each day...

    eg, on the first day of the year call up "001.js", on the second day call
    "002.js", and so on

    any help, clues, or tips ... thanks...





  • Evertjan.

    #2
    Re: renaming a .js file ????

    OzThor wrote on 07 feb 2004 in comp.lang.javas cript:
    [color=blue]
    > what i would like to do is find some way to rename the .js file that is
    > called each day...
    >
    > eg, on the first day of the year call up "001.js", on the second day call
    > "002.js", and so on
    >[/color]

    Serverside that is easy.

    Clientside I do not think it can be done.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • Douglas Crockford

      #3
      Re: renaming a .js file ????

      > I have a javascript quiz webpage... that loads the questions and answers[color=blue]
      > from a .js file...
      >
      > at this time i use the following to call the data
      >
      > <script src="quiz_a.js" ></script>
      >
      > this works fine, but I'd like a new lot of data to be used each day...
      >
      > i have the javascript code to number each day of the year from 1 to 356 (or
      > days in the year)
      >
      > what i would like to do is find some way to rename the .js file that is
      > called each day...
      >
      > eg, on the first day of the year call up "001.js", on the second day call
      > "002.js", and so on[/color]

      This really should happen in the server side. This is what things like
      appservers are for.

      But if you have to do it in the client,

      document.write( '<script src="' + (('00' + day).substr(0, 3)) +
      '.js"><\/script>');


      Comment

      • Dr John Stockton

        #4
        Re: renaming a .js file ????

        JRS: In article <88d07$4023c90a $44a4afef$28728 @msgid.meganews servers.co
        m>, seen in news:comp.lang. javascript, Douglas Crockford
        <nospam@covad.n et> posted at Fri, 6 Feb 2004 09:03:24 :-[color=blue]
        >
        > document.write( '<script src="' + (('00' + day).substr(0, 3)) +
        > '.js"><\/script>');[/color]

        Wrong substr. Try (String(1000 + day).substr(1))

        (that should be used only where it is reasonably certain that
        0<=day<999)

        --
        © 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

        • Tom Kiefer

          #5
          Re: renaming a .js file ????

          JavaScript doesn't seem to support a Date.getDayOfYe ar method, but you could
          (e.g.) do something like:

          dtmToday = new Date();
          intMonth = 1 + dtmToday.getMon th();
          intDay = dtmToday.getDat e();
          document.write( '<script src="' + (intMonth < 10 ? '0' : '') + intMonth +
          (intDay < 10 ? '0' : '') + intDay + '.js"></script>');

          Then you can store your JS files as:
          0101.js (for January 1)
          0220.js (for February 20)
          0704.js (for July 4)
          1225.js (for December 25)
          etc.

          - Tom Kiefer
          thogek @ earthlink . net


          "OzThor" <ronjeff@froggy .com.au> wrote in message
          news:c00a8b$nne $1@au-nws-0001.flow.com.a u...[color=blue]
          > I have a javascript quiz webpage... that loads the questions and answers
          > from a .js file...
          >
          > at this time i use the following to call the data
          >
          > <script src="quiz_a.js" ></script>
          >
          > this works fine, but I'd like a new lot of data to be used each day...
          >
          > i have the javascript code to number each day of the year from 1 to 356[/color]
          (or[color=blue]
          > days in the year)
          >
          > what i would like to do is find some way to rename the .js file that is
          > called each day...
          >
          > eg, on the first day of the year call up "001.js", on the second day call
          > "002.js", and so on
          >
          > any help, clues, or tips ... thanks...
          >
          >
          >
          >
          >[/color]


          Comment

          • Dr John Stockton

            #6
            Re: renaming a .js file ????

            JRS: In article <focVb.15274$F2 3.4205@newsread 2.news.pas.eart hlink.net>
            , seen in news:comp.lang. javascript, Tom Kiefer
            <thogeknot@eart hlinknot.net> posted at Sat, 7 Feb 2004 21:03:07 :-
            [color=blue]
            >JavaScript doesn't seem to support a Date.getDayOfYe ar method,[/color]

            function DayOfYear(Y, M, D) {
            return Math.round((new Date(Y, M-1, D)-new Date(Y, 0, 0))/864e5) }

            function DayOfYear(Y, M, D) {
            return (Date.UTC(Y, M-1, D) - Date.UTC(Y, 0, 0))/864e5 }

            DateObj = new Date(Y, 0, DayOfYear)

            DateObj.setMont h(0, DayOfYear)

            See below.

            --
            © 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

            • Tom Kiefer

              #7
              Re: renaming a .js file ????

              I said JavaScript didn't contain a Date.GetDayOfYe ar method. I didn't say
              you couldn't build your own. :-)

              - Tom Kiefer
              thogek @ earthlink . net


              "Dr John Stockton" <spam@merlyn.de mon.co.uk> wrote in message
              news:5$cCTJT+7i JAFw2Q@merlyn.d emon.co.uk...[color=blue]
              > JRS: In article <focVb.15274$F2 3.4205@newsread 2.news.pas.eart hlink.net>
              > , seen in news:comp.lang. javascript, Tom Kiefer
              > <thogeknot@eart hlinknot.net> posted at Sat, 7 Feb 2004 21:03:07 :-
              >[color=green]
              > >JavaScript doesn't seem to support a Date.getDayOfYe ar method,[/color]
              >
              > function DayOfYear(Y, M, D) {
              > return Math.round((new Date(Y, M-1, D)-new Date(Y, 0, 0))/864e5) }
              >
              > function DayOfYear(Y, M, D) {
              > return (Date.UTC(Y, M-1, D) - Date.UTC(Y, 0, 0))/864e5 }
              >
              > DateObj = new Date(Y, 0, DayOfYear)
              >
              > DateObj.setMont h(0, DayOfYear)
              >
              > See below.
              >
              > --
              > © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE[/color]
              4 ©[color=blue]
              > <URL:http://jibbering.com/faq/> Jim Ley's FAQ for[/color]
              news:comp.lang. javascript[color=blue]
              > <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates,[/color]
              sources.[color=blue]
              > <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items,[/color]
              links.


              Comment

              • Dr John Stockton

                #8
                Re: renaming a .js file ????

                JRS: In article <R3zVb.16626$F2 3.4363@newsread 2.news.pas.eart hlink.net>
                , seen in news:comp.lang. javascript, Tom Kiefer
                <thogeknot@eart hlinknot.net> posted at Sun, 8 Feb 2004 22:51:29 :-[color=blue]
                >I said JavaScript didn't contain a Date.GetDayOfYe ar method. I didn't say
                >you couldn't build your own. :-)[/color]

                Please read the newsgroup FAQ, section 2.3, para 5, sentence 6, before
                posting here again. The rest of the FAQ is also worth reading.

                --
                © 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

                • Tom Kiefer

                  #9
                  Re: renaming a .js file ????

                  "Dr John Stockton" <spam@merlyn.de mon.co.uk> wrote:[color=blue]
                  > Tom Kiefer posted:[color=green]
                  > >I said JavaScript didn't contain a Date.GetDayOfYe ar method. I didn't[/color][/color]
                  say[color=blue][color=green]
                  > >you couldn't build your own. :-)[/color]
                  >
                  > Please read the newsgroup FAQ, section 2.3, para 5, sentence 6, before
                  > posting here again. The rest of the FAQ is also worth reading.[/color]

                  CJL newsgroup FAQ, section 2.3, para 7, sentence 2:

                  "And don't start a thread complaining about rude or
                  flippant responses, there is already enough noise in clj."

                  Oh, okay.

                  - Tom Kiefer
                  thogek @ earthlink . net


                  Comment

                  Working...