469,588 Members | 2,734 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Help with syntax, please?

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#...day%20+%20year

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

Thanks, in advance!

-Cloy

Feb 8 '07 #1
2 943
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.
--

Feb 8 '07 #2
On Feb 7, 9:59 pm, Lee <REM0VElbspamt...@cox.netwrote:
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.

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

Feb 8 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by sam | last post: by
28 posts views Thread by stu_gots | last post: by
6 posts views Thread by d.warnermurray | last post: by
7 posts views Thread by Jeff | last post: by
1 post views Thread by Rahul | last post: by
6 posts views Thread by toch3 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.