Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wont let me call my function

    Code:
    <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.

    Code:
    <input type="button" value="testButton" onclick="currentDate();">
    Why the hell does the error console say that 'currentDate' is not a function ?

  • #2
    New Coder
    Join Date
    Jan 2007
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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,

  • #3
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,768
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Try putting your Javascript right before the closing </body> tag in your HTML...see if that helps
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #4
    New Coder
    Join Date
    Nov 2006
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •