Computing.Net > Forums > Web Development > Javascript data for a link

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Javascript data for a link

Reply to Message Icon

Name: Spinal
Date: June 8, 2004 at 03:57:56 Pacific
OS: Win2K
CPU/Ram: 1Ghz/1Gb
Comment:

Greetings again! I did say I would be back soon, hehe.
My question this time is, if u want to link something to a link which changes daily, for example:
www.mypage.com/images/20040608.gif
. Ive come up with the idea that I can use javascript for this, here is the script Ive got so far:
<script type="text/javascript">
var d = new Date()
document.write(d.getFullYear())
document.write(d.getMonth() + 1)
document.write(d.getDate())
</script>

First problem:
the Date it gives for 20040608 is 200468. Any idea's how to get it to 20040608? My research shows something on the lines of:
new Date(yy,mm,dd)
which should get the month (mm) and day (dd) as a two digit number, but I can't get this to work.

Secondly, any idea how to link to sucha page? I was thinking something on the lines of turning 2004, 06, 08 to strings, concatenate them together, and finally concat the whole thing to the base url, like:
myLink = "http://www.mysite.com/images/"++FullYear.toString()++month.toString()++day.toString().

And then href to myLink. Any ideas on how to get this working? Thanx,
Michele



Sponsored Link
Ads by Google

Response Number 1
Name: Jamie_McCoy
Date: June 8, 2004 at 04:44:16 Pacific
Reply:

PHP WOULD BE EASIER AN MORE RELIABLE


Sign Me Guestbook!

jaymc.co.nr


0

Response Number 2
Name: Spinal
Date: June 8, 2004 at 05:50:54 Pacific
Reply:

Uhmm, it probably would, but considering the
trouble I've had with PHP (I can't even get
the REMOTE_ADRR! It gets the servers IP!) I
think for the moment I'm stuck with
javascript.
Michele


0

Response Number 3
Name: Khalid
Date: June 8, 2004 at 08:33:03 Pacific
Reply:

This:

var today = new Date()
var day = today.getDate()
var month = today.getMonth() + 1
var year = today.getYear()
day = day.toString()
month = month.toString()
year = year.toString()
if (day.length == 1) {day = '0' + day}
if (month.length == 1) {month = '0' + month}
document.write(year + month + day)

will output the date as you want.

I have only added a litte 'test' to check if the day and month have 1 digit. I have searched my JavaScript-bible, but couldnt find another solution.


0

Response Number 4
Name: Spinal
Date: June 9, 2004 at 02:48:10 Pacific
Reply:

PERFECT! Thank you so much! Now I can finish that off! I've ben trying to code a really constipated version with if loops to check the the 0's, lol.
Thanx again,
Michele


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Javascript data for a link

How do i get choices for a variable www.computing.net/answers/webdevel/how-do-i-get-choices-for-a-variable/2060.html

Time For A Change... www.computing.net/answers/webdevel/time-for-a-change/104.html

Javascript: Cross input via link www.computing.net/answers/webdevel/javascript-cross-input-via-link/3004.html