Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date function with span id return issue.

Status
Not open for further replies.

jgraves13

Programmer
Jan 31, 2007
42
US
I am trying to return a 4 digit current year where the span id exist in the code. I am not sure what I am doing wrong with this code. I was hoping someone can let me know where I went wrong.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head>
    <title>Untitled Page</title>
  <script type="text/javascript">
   function getYearEnd()
   {
    var d = new Date()
    var d.getFullYear()
    var YearEnd = document.getElementById('txtYear').value(d.getFullYear());
    
   /* //This is testing script to verify working 
    document.write("This is in scrip tag Copyright 1997-")
    document.write(d.getFullYear())
   */
   
   // This should return/write 4 Char year
    //document.getElementById('txtYear').value(d.getFullYear());
	document.getElementById('txtYear').innerHTML = YearEnd;
        
    </script> 
    <!-- <script type="text/javascript" src="/YearEnd.js"></script> -->
</head>
<body onload="getYearEnd()">

<p>simple Copyright 1997- <span id="txtYear" /></p> 

</body>
</html>

thanks
~ JG
 
We don't self-close span tags in HTML! Change it to use a regular close:
Code:
<span id="txtYear"></span>
Your function would work written like this:
Code:
function getYearEnd() {
    var d = new Date()
    if (document.getElementById('txtYear')) {
        document.getElementById('txtYear').innerHTML = d.getFullYear();
    }
}

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top