0

I have a jQuery dialog which I fire from a list of items in a jTemplate:

<a href="#" class="view-map" id="{$T.Address.AddressCity.Lat}|{$T.Address.AddressCity.Lon}"><img src="/images/iconography/tiny-map.png" width="16" height="16" alt="See this address on a map..." title="See this address on a map..."></img></a>

jQuery:

$('.view-map').live('click', function () {
            $('#map')
                .data('id', $(this).attr('id'))
                .dialog('open')

            ;
            return false;
        });

        $('#map').dialog({
            autoOpen: false,
            resizeable: false,
            position: 'top',
            modal: true,
            width: 650,
            open: function() {
                var location =  $(this).data('id').split('|');
                $(this).load('/components/google/map.aspx?lat=' + location[0] + '&lon=' + location[1]);
            },
            buttons: {
                'Ok': function () {
                    $(this).dialog('close');
                }
            }
        });

When the map.aspx page loads, I want the following javascript to fire (so I can get the map from Google):

function initialize() {
            var myOptions = {
                zoom: 9,
                disableDefaultUI: true,
                center: new google.maps.LatLng(<%=Lat%>, <%=Lon%>),
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var map = new google.maps.Map(document.getElementById('x-map-placeholder'), myOptions);
            document.getElementById('x-map-loader').style.display = 'none';
        }

        function loadScript() {
            alert("I'm away!");
            var script = document.createElement('script');
            script.type = 'text/javascript';
            script.src = 'http://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize';
            document.body.appendChild(script);
        }
        function toLower(s) {
            return s.toLowerCase();
        }
        function toFixed(n) {
            return n.toFixed(0);
        }

        window.onload = loadScript;

Obviously it doesn't and I think this is because how the dialog is called - I understand that calling a dialog isn't window.onloading and therefore won't fire the loadScript, but I'm not sure what to do to get it to fire....

Can anyone help? :)

Help is appreciated.

1 Answer 1

3

use

$(function(){
function to fire 
});
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome! And super quick too. Thanks very much :) +1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.