So my question is pretty simple, yet since im new to html and javascript, i need help.
So i have the following javascript code which is in my html code. i would like to have that function on its own seperate sheet . How do i call the function in my html sheet?
<script LANGUAGE="Javascript">
var stampdays = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var stampmonths = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var thedate = new Date();
document.write(stampdays[thedate.getDay()] + ", " + stampmonths[thedate.getMonth()] + " " + thedate.getDate() + ", " + thedate.getFullYear());
</script>
Make a file called
script.jsscript.js:
In your HTML, include this tag:
You can include that tag anywhere in your HTML. Preferably right before the closing
</body>tag.On a side note, no need to use
new Array(). Just use an array literal like I show in the code above.On another side note, you probably don’t want to use
document.write. It’s like 1997 style. You’ll likely want to populate one of your HTML elements like so:If you want to make that a function, you’d simply declare one:
Then invoke it like
setDate(stampdays[...etc...getFullYear());