PDA

View Full Version : Wont let me call my function



aatwo
02-08-2007, 12:13 AM
<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-08-2007, 12:27 AM
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-08-2007, 12:31 AM
Try putting your Javascript right before the closing </body> tag in your HTML...see if that helps

aatwo
02-08-2007, 12:34 AM
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.