By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,697 Members | 1,340 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,697 IT Pros & Developers. It's quick & easy.

Help with syntax, please?

P: n/a
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
Share this Question
Share on Google+
2 Replies

P: n/a
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

P: n/a
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.