...

View Full Version : Function is undefined



stressedStudent
11-09-2012, 11:25 PM
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.


<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
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/extensions/tut_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:


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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum