?
Solved

error: function not defined....   but it is!!!

Posted on 2011-10-08
7
Medium Priority
?
286 Views
Last Modified: 2012-06-22
updateEditor is not defined
  It's maddening.  The function is defined.  I call it onchange from the select statement, and console throws an error and the alert does not execute.  WTH?!?!?!  Please help me see the light here.  Thanks.

<script type="text/javascript">
	(function($) {
		$(function() {
			
			alert('kilroy');
				
			function updateEditor() {
				alert('do somehting');
			}
		
		});
	}(jQuery));
</script>

<select name="service" onchange="updateEditor();">	
	<cfset loopCount = 0>
	<cfloop query="services">
		<cfset loopcount = incrementValue(loopcount)>
		<option value="#loopcount#">#services['prodServ_title'][loopcount]#</option>
	</cfloop>
</select>

Open in new window

0
Comment
Question by:brianmfalls
  • 3
  • 3
7 Comments
 
LVL 1

Author Comment

by:brianmfalls
ID: 36936752
SOlved it....  take the function out of the following block.

 
	(function($) {
		$(function() {

                     ..................

		});
	}(jQuery));

Open in new window


Tell me why and the points are yours.
0
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 36936770
I don't think that you can normally nest functions in that way and I am not sure why you would even want to. Declare the functions independent of each other and nest the function calls if you need the nesting to perform actions.
0
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 36936775
It is not defined because you are calling the name updateEditor() and it would most likely be some javascript name with placeholders in front of it to point to the other two functions.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:brianmfalls
ID: 36936778
Why though?  Just to satisfy my curiosity.  Why can I nest the functions there?
0
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 600 total points
ID: 36937019
It is defined inside an anonymous function and is therefore only visible inside that function

What you CAN (and should) do is this http://jsfiddle.net/mplungjan/NpL4J/


$(document).ready(function() {
  $("#service").change(function() {
    alert("do something");
  });
});

<select id="service" name="service">
    <option value="">Please select</option>
    <option value="1">One</option>
</select>

Open in new window

0
 
LVL 18

Accepted Solution

by:
Jerry Miller earned 1400 total points
ID: 36937060
When add levels of nesting your name grows with each level. if you wanted to nest it, you could do something like this:

<script type="text/javascript">
        (function($) {
         var kilroy =   $(function() {
                       
                        alert('kilroy');
                               
                        function updateEditor() {
                                alert('do somehting');
                        }
               
                });
        }(jQuery));
</script>

Then call it with:
<select name="service" onchange="kilroy.updateEditor();">      
        <cfset loopCount = 0>
        <cfloop query="services">
                <cfset loopcount = incrementValue(loopcount)>
                <option value="#loopcount#">#services['prodServ_title'][loopcount]#</option>
        </cfloop>
</select>

0
 
LVL 1

Author Closing Comment

by:brianmfalls
ID: 36937164
Thanks guys.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question