Help with syntax, please?

C

Cloy

I'm working on a script that loads a page, and then jumps to an anchor
(based on the date). Everything works except getting the anchor format
correctly.

Here is the code...

<script type="text/javascript">
<!--
var date = new Date();
var d = date.getDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var year = date.getFullYear();
onload=document.location='# + month + day + year';
// -->
</script>

Here is what the URL should look like...
http://www.someurl.com/thisfile.htm#02072007
(on 2/7/2007)

This is what I'm getting instead...
http://www.someurl.com/thisfile.htm# + month + day + year

Can someone help me with the syntax of the onload= line?

Thanks, in advance!

-Cloy
 
L

Lee

Cloy said:
I'm working on a script that loads a page, and then jumps to an anchor
(based on the date). Everything works except getting the anchor format
correctly.

Here is the code...

<script type="text/javascript">
<!--
var date = new Date();
var d = date.getDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var year = date.getFullYear();
onload=document.location='# + month + day + year';

Everything inside the single quotes in that last line is the value
of the string literal that's assigned to document.location.
No operations are evaluated inside string literals.
That should be enough of a clue.


--
 
D

dev_jg

Cloy said:










Everything inside the single quotes in that last line is the value
of the string literal that's assigned to document.location.
No operations are evaluated inside string literals.
That should be enough of a clue.

--- Hide quoted text -

- Show quoted text -

yes, thats true

this is what he means in layman terms

change onload=document.location='# + month + day + year';
to
onload=document.location='#' + month + day + year;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top