/    Sign up×
Community /Pin to ProfileBookmark

Calling a javascript function from within a <td>

I have a table that is in a form. The top row of the table displays a logo in the first <td> element and in the second <td> element I have today’s date. If I put all of the script code right in the <td> such as this….

[code=php]<td align=’right’>
<script>
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym=”0″+daym
var dayarray=new Array(“Sunday”,”Monday”,”Tuesday”,”Wednesday”,”Thursday”,”Friday”,”Saturday”)
var montharray=new Array(“January”,”February”,”March”,”April”,”May”,”June”,”July”,”August”,”September”,”October”,”November”,”December”)
document.write(“<small><font color=’000000′ face=’Arial’><b>”+dayarray[day]+”, “+montharray[month]+” “+daym+”, “+year+”</b></font></small>”)
</script>
</td>[/code]

this works just fine. It displays the date perfectly. But I have this as a standard throughout the different pages on the site so I what I want to do is make a date.js and just call the function getDate(). This is what I have tried…

[code=php]<td align=’right’><SCRIPT language=”javascript” src=”date.js”>getDate();</SCRIPT></td>[/code]

This however does nothing. What am I missing? Is it possible to call it like this??

thanks a ton…

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@mjdamatoAug 06.2007 — I don't see why you can't do that, but I would make the following suggestion.

Create the external file as you have above, but have it define a variable for the date you want to display. Then include the javascript as you did above in the head of the document. Then within the TD you could just put a single line js to write out the variable.
Copy linkTweet thisAlerts:
@DetectAug 06.2007 — Put <SCRIPT language="javascript" src="date.js"></SCRIPT> at the top of every page in the HEAD tag.

Call the function inside your TD by using a regular <SCRIPT type="text/javascript">getDate();</SCRIPT>
Copy linkTweet thisAlerts:
@bryce4presidentauthorAug 06.2007 — Thank you very much Detct. Worked perfectly.
×

Success!

Help @bryce4president spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...