CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Function is undefined (http://www.codingforums.com/showthread.php?t=281689)

stressedStudent 11-09-2012 11:25 PM

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>


Logic Ali 11-09-2012 11:57 PM

Quote:

Originally Posted by stressedStudent (Post 1290505)
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.

Old Pedant 11-10-2012 12:00 AM

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.

Old Pedant 11-10-2012 12:03 AM

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.)


All times are GMT +1. The time now is 06:01 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.