Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-09-2012, 11:25 PM   PM User | #1
stressedStudent
New to the CF scene

 
Join Date: Oct 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
stressedStudent is an unknown quantity at this point
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>
stressedStudent is offline   Reply With Quote
Old 11-09-2012, 11:57 PM   PM User | #2
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 976
Thanks: 0
Thanked 203 Times in 198 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
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.
Logic Ali is online now   Reply With Quote
Old 11-10-2012, 12:00 AM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,056 Times in 4,025 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 11-10-2012, 12:03 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,056 Times in 4,025 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Tags
function undefined, javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:32 PM.


Advertisement
Log in to turn off these ads.