Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1084417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:33:33+00:00 2026-05-16T22:33:33+00:00

I am getting a function not defined error with my jquery script and i’m

  • 0

I am getting a function not defined error with my jquery script and i’m not sure why.

JQuery Code:
http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAhTrgZ5jvdqcEQouEpPcZ_hS81NmJwGXlxuJr8lEEo4Njw3WRVhT8auzZb55JSMDkwIaCdNkPHL5gNg” type=”text/javascript”>

<script type="text/javascript">
$(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 && 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("<span style='font-size:14px; font-weight:bold;'>" + customerName + "<br /></span><span style='font-size:12px;'>" + address + "</span>");
                    }
                }
                );
            }
            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);
});
</script>

Code from the HTML page:

<div id="main-map-wrapper">
    <div id="seperator"></div>
    <table width="100%" height="94">
        <tr valign="top">
            <td width="33%" colspan="3">
                <div id="headertextdiv">
                    <div id="nameAddress">
                        <span class="placeholderName" style="font-size:20px; font-weight:bold; line-height:22px;">&nbsp;&nbsp;</span>
                        <br />
                        <span class="placeholderAddress" style="font-size:14px; font-weight:bold; line-height:22px;">&nbsp;&nbsp;</span>
                        <br />
                        <input type="submit" onClick="return show_address('5930 West Plano Pkwy, Plano, Texas, 75093');" value="Center Map on Dealership">
                    </div>
                </div>
            </td>
        </tr>
    </table>
    <div id="map_canvas">&nbsp;&nbsp;</div>
    <form name="direction_form" onSubmit="get_directions(); return false;" class="form">
        <span style="font-size:18px; font-weight:bold;">Need directions?</span>
        <br />
        <span style="font-size:14px; margin-top:7px;">Enter your address below to get turn-by-turn directions:</span>
        <br />
        <input type="text" name="from_address" class="form-field" />
        <input type="submit" value="Get Directions" class="form-submit" style="margin-left:10px;" />
    </form>
    <a name="directions_table">&nbsp;&nbsp;</a>
    <div id="directions">&nbsp;&nbsp;</div>
</div>
<div class="footer-fix">&nbsp;&nbsp;</div>

​

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.

I believe this is because i have the functions set inside the ready 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: show_address runs immediately to start the map when i call initialize_map; however, it is also what is supposed to be called when you click the button “Center Map on Dealership”. get_directions is only called when you submit the form.

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.

I am at a standstill with this. Not sure how to get this functioning properly. Any help is greatly appreciated. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:33:34+00:00Added an answer on May 16, 2026 at 10:33 pm

    It’s because your show_address and get_directions are defined only inside that document.ready handler’s scope, you need to move the functions outside there if you want to call them via inline script.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting a function not defined Javascript error with the following code, which uses
I am getting this error Uncaught ReferenceError: loadNext is not defined (anonymous function) The
Why am I getting an error for this piece of code?: function catchevent() {
Not really getting the point of the map function. Can anyone explain with examples
I m new to CakePhp and JQuery. I am getting an error in using
I'm getting a JS error because my $(function () {...}) handler is being fired
So, here's my JSONP URL: http://community.tradeking.com/leaderboard.js And here's the jQuery I'm trying to parse
I'm getting an error here that says I haven't defined a method, but it
I'm getting this problem: PHP Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable
I'm getting a Call to a member function process_data() on a non-object in page.class.php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.