...

View Full Version : Wont let me call my function



aatwo
02-07-2007, 11:13 PM
<script language="Javascript">
//Function that returns a timestamp in the form 'fullYear-month-day hour:minute:second'
//Eg: The 24'th of December 1999 at 12 seconds past 8:42pm would return '1999-12-24 20:42:12'
function currentDate(){
var d = new Date(), day, month, year,date="", hour, minute, second;
day=d.getDate();
month=d.getMonth() + 1;
year=d.getFullYear();
hour=d.getHours();
minute=d.getMinutes();
second=d.getSeconds();
date=date+year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
document.getElementById("currentDate").value=date;
document.getElementById("modifyDate").value=date;
}
</script>

I have the above javascript in the header of my page and in the body I call the function when a button is clicked.



<input type="button" value="testButton" onclick="currentDate();">


Why the hell does the error console say that 'currentDate' is not a function ?

tonyp12
02-07-2007, 11:27 PM
I test it and it works.

I can only see that problem could come from that the JS code is not placed at the right spot.

Should NOT be after <[if lt IE 7.]> etc,

chump2877
02-07-2007, 11:31 PM
Try putting your Javascript right before the closing </body> tag in your HTML...see if that helps

aatwo
02-07-2007, 11:34 PM
After the last half hour of becoming ever so slightly more insane I discovered that there was some kind of conflict with the name of the function and the name of a form element. I changed the name of the function and it seems to have sorted its self out.

Thank you tonyp12 for taking the time to test my code.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum