title: Undefined is not a function in Jquery script
body: <p>I'm having a problem with some javascript I got help with. This is the error I get:</p>
  
  <pre><code>Uncaught TypeError: undefined is not a function 
  </code></pre>
  
  <p>It seems to be with my line: </p>
  
  <pre><code>callback(lastResult); // send the result back
  </code></pre>
  
  <p>The odd thing is the code seems to work as expected, but I obviously don't want to have errors with my code. Can someone please help to show me where I am going wrong?</p>
  
  <p><strong>Jsfiddle:</strong> <a href="http://jsfiddle.net/spadez/uaZkV/3/" rel="nofollow">http://jsfiddle.net/spadez/uaZkV/3/</a></p>
  
  <p><strong>Full code:</strong></p>
  
  <pre><code>$(function () {
      var input = $("#loc"),
          lat = $("#lat"),
          lng = $("#lng"),
          lastQuery = null,
          lastResult = null, // new!
          autocomplete;
  
      function processLocation(callback) { // accept a callback argument
          var query = $.trim(input.val()),
              geocoder;
  
          // if query is empty or the same as last time...
          if (!query || query == lastQuery) {
              callback(lastResult); // send the same result as before
              return; // and stop here
          }
  
          lastQuery = query; // store for next time
  
          geocoder = new google.maps.Geocoder();
          geocoder.geocode({
              address: query
          }, function (results, status) {
              if (status === google.maps.GeocoderStatus.OK) {
                  lat.val(results[0].geometry.location.lat());
                  lng.val(results[0].geometry.location.lng());
                  lastResult = true; // success!
              } else {
                  alert("Sorry - We couldn't find this location. Please try an alternative");
                  lastResult = false; // failure!
              }
              callback(lastResult); // send the result back
          });
      }
  
      autocomplete = new google.maps.places.Autocomplete(input[0], {
          types: ["geocode"],
          componentRestrictions: {
              country: "uk"
          }
      });
  
      google.maps.event.addListener(autocomplete, 'place_changed', processLocation);
  
      $('#searchform').on('submit', function (event) {
          var form = this;
  
          event.preventDefault(); // stop the submission
  
          processLocation(function (success) {
              if (success) { // if the geocoding succeeded, submit the form
                  form.submit()
              }
          });
  
      });
  });
  </code></pre>