Welcome to Dream.In.Code
Getting Help is Easy!

Join 86,251 Programmers. There are 2,139 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

Dynamic copyright date

 
Reply to this topicStart new topic

Dynamic copyright date

raeNet
post 4 May, 2008 - 04:23 PM
Post #1


D.I.C Head

**
Joined: 1 Nov, 2007
Posts: 70



I'm trying to write a javascript to perform an auto update of my website's ending copyright year to occur after the first of the year, but when I load my page, the change occurs, erasing all other page content.

Can anyone lend me some help on this? thank you in advance.

CODE

<script type="text/javascript" >
<!-- <![CDATA[
function copyright()
{
copyright=new Date();
update=copyright.getYear();
document.write("Copyright &copy; 1998-"+ update + " ".);
}
] ] > -->
</script>
</head>
<body onload="copyright()">
<table width="100%" height="400" border="2">
<tr><td></td></tr>
</table>
<p>&nbsp;</p>
<p>Copyright &copy; 1998-2007. WALLY'S WACKY CAR WASH.  All Rights Reserved. </p></td>
</tr>
</table>
</body>
</html>


This post has been edited by raeNet: 4 May, 2008 - 04:33 PM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


baavgai
post 4 May, 2008 - 05:28 PM
Post #2


Dreaming Coder

Group Icon
Joined: 16 Oct, 2007
Posts: 1,077

If you're using document.write, you want to call it when you want to use it. Like this:
CODE

<html>
<head>
    <script type="text/javascript" >
        function copyright() {
            copyright=new Date();
            update=copyright.getYear();
            document.write("Copyright &copy; 1998-"+ update );
        }
    </script>
</head>
<body>
    <p>
        <script>copyright(); </script>
        WALLY'S WACKY CAR WASH.  All Rights Reserved.
    </p>
</body>
</html>


A more flexable way of doing this is to have a fixed element in the document with a unique id. You can then use the DOM to change the value of that element.

Here's how it works.
CODE

<html>
<head>
    <script type="text/javascript" >
        function copyright() {
            document.getElementById("copyright").innerHTML =
                "Copyright &copy; 1998-"+ (new Date().getYear() + 1900);
        }
    </script>
</head>
<body onload="copyright()">
    <p><span id="copyright"></span> WALLY'S WACKY CAR WASH.  All Rights Reserved.</p>
</body>
</html>


Hope this helps.
User is online!Profile CardPM
Go to the top of the page
+Quote Post

raeNet
post 4 May, 2008 - 05:47 PM
Post #3


D.I.C Head

**
Joined: 1 Nov, 2007
Posts: 70

Yes it does help - thanks so much.

One more minor detail. Any ideas on how to force it into the footer of my page? It currently displays at the top. Again, thanks!
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

raeNet
post 4 May, 2008 - 07:00 PM
Post #4


D.I.C Head

**
Joined: 1 Nov, 2007
Posts: 70

After looking at this again, I noticed that the orginal copyright date (1998-2007) was excluded and I need it to display and then be replaced by the (1998-2008)

Can anyone help me do this? I need it in a hurry! Thanks.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/16/08 09:00AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month