-
Quick JS help
I have a page and I am trying to display the date, however when I use any of the getDate, getHour, etc I keep getting this result:
function getMonth() { [native code] } / function getDate() { [native code] }
I don't understand why the functions are not working, I separated them out, but none of them work, here is my code.
Code:
var d = new Date()
document.write(d.getMonth);
document.write('/');
document.write(d.getDate);
document.write('/');
document.write(d.getFullYear);
document.write(' ');
document.write(d.getHours);
document.write(':');
document.write(d.getMinutes);
document.write(':');
document.write(d.getSeconds);
Thanks!
-
Although I don't really know why it does this... This will fix it. Note on the Month that you need to add 1 to it because it is a 0 bound array of the months.
Code:
var d = new Date()
var m = d.getMonth()
var y = d.getFullYear()
var h = d.getHours()
var mn = d.getMinutes()
var s = d.getSeconds()
document.write(m+1);
document.write('/');
document.write(d);
document.write('/');
document.write(y);
document.write(' ');
document.write(h);
document.write(':');
document.write(mn);
document.write(':');
document.write(s);
-
Thanks, it was because I forgot the parentheses after all the get statements! Thanks anyways.
-
Yeah if you leave out the parenthasis it returns the function's code. That is done so you can swap functions around, e.g.
function someFunc() {
alert('Hello');
}
document.forms[0].onsubmit = someFunc();
which would make the first form's onsubmit event hander be the same as someFunc().