469,352 Members | 1,892 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

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

Jul 20 '05 #1
8 1410
OzThor wrote on 07 feb 2004 in comp.lang.javascript:
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


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)
Jul 20 '05 #2
> 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


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>');

http://www.crockford.com/javascript/javascript.html
Jul 20 '05 #3
JRS: In article <88***************************@msgid.meganewsserve rs.co
m>, seen in news:comp.lang.javascript, Douglas Crockford
<no****@covad.net> posted at Fri, 6 Feb 2004 09:03:24 :-

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


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.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #4
JavaScript doesn't seem to support a Date.getDayOfYear method, but you could
(e.g.) do something like:

dtmToday = new Date();
intMonth = 1 + dtmToday.getMonth();
intDay = dtmToday.getDate();
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" <ro*****@froggy.com.au> wrote in message
news:c0**********@au-nws-0001.flow.com.au...
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...


Jul 20 '05 #5
JRS: In article <fo******************@newsread2.news.pas.earthlink .net>
, seen in news:comp.lang.javascript, Tom Kiefer
<th*******@earthlinknot.net> posted at Sat, 7 Feb 2004 21:03:07 :-
JavaScript doesn't seem to support a Date.getDayOfYear method,


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.setMonth(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.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #6
I said JavaScript didn't contain a Date.GetDayOfYear method. I didn't say
you couldn't build your own. :-)

- Tom Kiefer
thogek @ earthlink . net
"Dr John Stockton" <sp**@merlyn.demon.co.uk> wrote in message
news:5$**************@merlyn.demon.co.uk...
JRS: In article <fo******************@newsread2.news.pas.earthlink .net>
, seen in news:comp.lang.javascript, Tom Kiefer
<th*******@earthlinknot.net> posted at Sat, 7 Feb 2004 21:03:07 :-
JavaScript doesn't seem to support a Date.getDayOfYear method,
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.setMonth(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.demon.co.uk/js-index.htm> jscr maths, dates, sources. <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items,

links.
Jul 20 '05 #7
JRS: In article <R3******************@newsread2.news.pas.earthlink .net>
, seen in news:comp.lang.javascript, Tom Kiefer
<th*******@earthlinknot.net> posted at Sun, 8 Feb 2004 22:51:29 :-
I said JavaScript didn't contain a Date.GetDayOfYear method. I didn't say
you couldn't build your own. :-)


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.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #8
"Dr John Stockton" <sp**@merlyn.demon.co.uk> wrote:
Tom Kiefer posted:
I said JavaScript didn't contain a Date.GetDayOfYear method. I didn't sayyou couldn't build your own. :-)


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.


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
Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Richard L Rosenheim | last post: by
reply views Thread by MikeY | last post: by
reply views Thread by Andy | last post: by
1 post views Thread by MikeY | last post: by
1 post views Thread by Jason B | last post: by
5 posts views Thread by bulldog8 | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.