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 to the CF scene
    Join Date
    Oct 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Function is undefined

    This is really important to fix as soon as possible. I have an absolute headache trying to figure out the mistake and I believe it has to be simple and easily overlooked. My debugger says that the ConvertToCm() and the onclick() function is undefined but I need help in figuring out how to fix that. please someone reply soon.
    Code:
    <html>
     <head>
       <title>Metric Conversion</title>
       <script type="text/javascript" src="convert.js"></script>
       <script type="text/javascript">
        	function  ConvertToCm()
    			{
    				var inches, cm ;
    				
    				inches = parseFloat(document.getElementById('inchBox').value);
    				cm = InchesToCentimeters(inches);
    				document.getElementById(outputDiv).innerHTML = 
    					'That is ' + cm + ' centimeters.';
    			}
    
       </script>
     </head>
     
     <body>
    	<p>Length in Inches:
    			<input type="text" id="inchBox" size=6 value=1>
    			<input type="button" value="Convert to Centimeters" 
    				onclick="ConvertToCm();">
    
       </p>
       <hr>
       <div id="outputDiv"></div>
     </body>
    </html>

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by stressedStudent View Post
    This is really important to fix as soon as possible. I have an absolute headache trying to figure out the mistake and I believe it has to be simple and easily overlooked. My debugger says that the ConvertToCm() and the onclick() function is undefined but I need help in figuring out how to fix that
    The function is undefined due to an unresolved reference within the function, which also must have been indicated in the console/debugger.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Usually, that means you had an error in the syntax of the function that you ignored.

    Once a function has a syntax error, it is non-existent from other code's standpoint. Hence undefined.

    (And I'd bet you are using MSIE, no?)

    &&&&&&&&&&&&

    LogicAli beat me this time.

    Anyway, learn to use the debugger in your browser!

    If you are using Chrome, look here:
    https://developer.chrome.com/extensi...debugging.html

    The MSIE debugger is very similar, though just a tad less user-friendly in my opinion.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    And the "unresolved reference" LogicAli referred to is of course here:
    Code:
    cm = InchesToCentimeters(inches);
    No place in your code do you have any InchesToCentimeters function defined.

    (Not that I see any reason to define one. Just plop the conversion code in there in place of tha function call.)
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

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