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 6735703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:02:38+00:00 2026-05-26T11:02:38+00:00

I have a set of jQuery UI tabs that each load project.php using ajax.

  • 0

I have a set of jQuery UI tabs that each load project.php using ajax. Depending on the parameters passed to the script, a different Google map is displayed using the following JavaScript inside project.php:

var tab_index = $('#tabs').tabs('option', 'selected');
$('.site_map:visible').css('height','300px');

MapID = $('.site_map:visible').attr('id');

if (MapID !== 'map-new'){
    var map_id = 'map-'+tab_index;
    $('.site_map:visible').attr('id', map_id);
} else {
    MapNewSite();
}

var latlng = new google.maps.LatLng(19,-70.4);
var myOptions = {
  zoom: 8,
  center: latlng,
  mapTypeId: google.maps.MapTypeId.ROADMAP
};

arrMaps[tab_index] = new google.maps.Map(document.getElementById("map-" + tab_index), myOptions);
arrInfoWindows[tab_index] = new google.maps.InfoWindow();
placeMarker($('.site_details:visible .inpLat').val(), $('.site_details:visible .inpLng').val(), tab_index);

function MapNewSite(){
    arrMaps[tab_index] = new google.maps.Map(document.getElementById("map-new"), myOptions);
    placeMarker(19,-70.4,tab_index);
    arrInfoWindows[tab_index] = new google.maps.InfoWindow();
}

Each map loaded using parameters returned by a query of my database loads without any problems. However, in one last instance, I load project.php in a tab without any parameters so as to have a blank tab for users to manipulate. The signal that the map is not to be loaded using database coordinates is that the id of its div is “map-new”.

The map generated in this tab loads, but then gives me the “a is null” error which usually means it couldn’t find a div with the id specified to initialize the map. What is causing this error even after the map has loaded? How do I stop the error from occurring?

Here is the JavaScript in the parent page containing the tab site:

    var arrMaps = {};
    var arrInfoWindows = {};
    var arrMarkers = {};

    function placeMarker(lat, lng, tab_index){
        map = arrMaps[tab_index];
        var bounds = new google.maps.LatLngBounds();
        var latlng = new google.maps.LatLng(
            parseFloat(lat),
            parseFloat(lng)
        );

        bounds.extend(latlng);
        createMarker(latlng, tab_index);
        map.fitBounds(bounds);

        zoomChangeBoundsListener = 
            google.maps.event.addListener(map, 'bounds_changed', function(event) {
                if (this.getZoom()){
                    this.setZoom(10);
                }
            google.maps.event.removeListener(zoomChangeBoundsListener);
        });
    }

    function createMarker(latlng, tab_index) {
        var html = '<a href="#" target="_blank" onclick="OpenMapDialog();return false;">Click here to move marker</a>';   
        arrMarkers[tab_index] = new google.maps.Marker({
            map: arrMaps[tab_index],
            position: latlng
        });

        arrInfoWindows[tab_index] = new google.maps.InfoWindow();

        google.maps.event.addListener(arrMarkers[tab_index], 'click', function() {
            arrInfoWindows[tab_index].setContent(html);
            arrInfoWindows[tab_index].open(arrMaps[tab_index], arrMarkers[tab_index]);
        });
    }

    $(function() {
        $( "#tabs" ).tabs({
            ajaxOptions: {
                error: function( xhr, status, index, anchor ) {
                    $( anchor.hash ).html(
                        "Couldn't load this tab. We'll try to fix this as soon as possible. " +
                        "If this wouldn't be a demo." );
                }
            },
            cache: true
        });
    });
  • 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-26T11:02:39+00:00Added an answer on May 26, 2026 at 11:02 am

    It turns out I was accidentally initializing the map both inside the if and outside of it.

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

Sidebar

Related Questions

I have a set of divs that I want to make collapsible/expandable using jQuery's
I have a template set up that I'm making ajax calls to via jQuery.
I have a JQuery silder that I'm using to set the score on a
I am using Jquery UI tabs, and have it set to toggle the opacity
I have a page that uses jQuery tabs to tabify a set of HTML
I have a project in PHP that uses multiple tabs on a single page,
I have some tabs that I load the content up via ajax. I am
I have a method set up that uses jquery form for a file upload
I have some jquery/php interaction set up on a page. It submits some data
I have this jQuery datepicker code that initially set the minDate of the datepicker.

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.