title: Function not defined
body: <p>I am getting a function not defined error with my jquery script and i'm not sure why.</p>
  
  <p>JQuery Code:
          http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAhTrgZ5jvdqcEQouEpPcZ_hS81NmJwGXlxuJr8lEEo4Njw3WRVhT8auzZb55JSMDkwIaCdNkPHL5gNg" type="text/javascript"> </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(document).ready(function(){
  var dealerName = $('.name', '.adr').text();
  var customerName = dealerName.slice(0, - 1);
  var customerAddress = $('.street', '.adr').text() + ', ' + $('.locality', '.adr').text() + ', ' + $('.state', '.adr').text() + ', ' + $('.zipCode', '.adr').text();
  $("#nameAddress .placeholderName").html(customerName);
  $("#nameAddress .placeholderAddress").html(customerAddress);
  
          var error_address_empty     = 'Please enter a valid address first.';
          var error_invalid_address   = 'This address is invalid. Make sure to enter your street number and city as well?'; 
          var error_google_error      = 'There was a problem processing your request, please try again.';
          var error_no_map_info       = 'Sorry! Map information is not available for this address.';
  
  
          var default_address = customerAddress;
  
          var current_address = null;
          var map               = null;
          var geocoder          = null;
          var gdir                  = null;
          var map_compatible  = false;
  
          if( GBrowserIsCompatible() ) {
              map_compatible = true;
          }
  
          function initialize_map() {
              if( map_compatible ) {
                  map         = new GMap2(document.getElementById('map_canvas'));        
                  geocoder = new GClientGeocoder();
                  show_address(default_address);
  
                  map.addControl(new GSmallMapControl());
  
                  map.addControl(new GMapTypeControl());              
              }
          }
  
          function show_address(address) {
              if( map_compatible &amp;&amp; geocoder ) {
                  current_address = address;      
                  geocoder.getLatLng(
                  address,
                  function( point ) {
                      if( !point ) {
                          alert(error_no_map_info);
                      } else {
                          map.setCenter(point, 13);
                          var marker = new GMarker(point);
                          map.addOverlay(marker);
                          marker.openInfoWindowHtml("&lt;span style='font-size:14px; font-weight:bold;'&gt;" + customerName + "&lt;br /&gt;&lt;/span&gt;&lt;span style='font-size:12px;'&gt;" + address + "&lt;/span&gt;");
                      }
                  }
                  );
              }
              return false;
          }
  
          function get_directions() {
              if( map_compatible ) {
                  if( document.direction_form.from_address.value == '' ) {
                      alert(error_address_empty);
                      return false;
                  }
  
                  document.getElementById('directions').innerHTML = '';
  
                  gdir = new GDirections(map, document.getElementById('directions'));
  
                  GEvent.addListener(gdir, 'error', handleErrors);
  
                  set_directions(document.direction_form.from_address.value, current_address);            
              }
              return false;
          }
  
          function set_directions(fromAddress, toAddress) {
          gdir.load("from: " + fromAddress + " to: " + toAddress,
                      { "locale": "en" });
          }
  
          function handleErrors(){
              if( gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS )
                  alert(error_invalid_address);
              else if( gdir.getStatus().code == G_GEO_SERVER_ERROR )
                  alert(error_google_error);
              else if( gdir.getStatus().code == G_GEO_MISSING_QUERY )
                  alert(error_address_empty);
              else 
                  alert(error_invalid_address);
          }
  $(window).load(initialize_map);
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Code from the HTML page:</p>
  
  <pre><code>&lt;div id="main-map-wrapper"&gt;
      &lt;div id="seperator"&gt;&lt;/div&gt;
      &lt;table width="100%" height="94"&gt;
          &lt;tr valign="top"&gt;
              &lt;td width="33%" colspan="3"&gt;
                  &lt;div id="headertextdiv"&gt;
                      &lt;div id="nameAddress"&gt;
                          &lt;span class="placeholderName" style="font-size:20px; font-weight:bold; line-height:22px;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;
                          &lt;br /&gt;
                          &lt;span class="placeholderAddress" style="font-size:14px; font-weight:bold; line-height:22px;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;
                          &lt;br /&gt;
                          &lt;input type="submit" onClick="return show_address('5930 West Plano Pkwy, Plano, Texas, 75093');" value="Center Map on Dealership"&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;div id="map_canvas"&gt;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
      &lt;form name="direction_form" onSubmit="get_directions(); return false;" class="form"&gt;
          &lt;span style="font-size:18px; font-weight:bold;"&gt;Need directions?&lt;/span&gt;
          &lt;br /&gt;
          &lt;span style="font-size:14px; margin-top:7px;"&gt;Enter your address below to get turn-by-turn directions:&lt;/span&gt;
          &lt;br /&gt;
          &lt;input type="text" name="from_address" class="form-field" /&gt;
          &lt;input type="submit" value="Get Directions" class="form-submit" style="margin-left:10px;" /&gt;
      &lt;/form&gt;
      &lt;a name="directions_table"&gt;&amp;nbsp;&amp;nbsp;&lt;/a&gt;
      &lt;div id="directions"&gt;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="footer-fix"&gt;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
  </code></pre>
  
  <p>​</p>
  
  <p>Problem:
  Anyway, as you can see in the code i am first setting all of the variables (including the customerName and customerAddress, which are the most important in this case).  Then i have four functions and at the end of the script i initialize the map.  Everything works except for two things on the html page.  There is an "onClick" to center the map that is not working and the form submit does not work.</p>
  
  <p>I believe this is because i have the functions set inside the <code>ready</code> handler.  I have been told that i need to bind the functions to their events within that handler just as i have with initialize_map.  I have tried to do this but everything i try does not work.  Side note and helpful tip maybe: <code>show_address</code> runs immediately to start the map when i call <code>initialize_map</code>; however, it is also what is supposed to be called when you click the button "Center Map on Dealership".  <code>get_directions</code> is only called when you submit the form.</p>
  
  <p>As of now everything shows up right when the page loads; however, when i click on "Center map on Dealership" or submit the form i get a javascript error that is telling me that the function is not defined.</p>
  
  <p>I am at a standstill with this.  Not sure how to get this functioning properly.  Any help is greatly appreciated.  Thanks!</p>