views:

36

answers:

1

Hi

I have this code

            <script type="text/javascript" src="http://www.google.com/jsapi"&gt;&lt;/script&gt;
        <script type="text/javascript">
        google.load("maps", "3",  {other_params:"sensor=false"});
        google.load("jquery", "1.3.2");
        google.load("visualization", "1", {packages: ["columnchart"]});

        function initialize() {

            // some actions...

            function mapload(myfile) {
                    jQuery.get("trace_" + myfile + ".xml", {}, function(data) {
                        // some actions...
                    });
            }

            mapload('ah');

        }

        google.setOnLoadCallback(initialize);
        </script>

        <input type="button" value="Hunt Mesa" onclick="mapload('hunt')" />

The first "mapload" works fine

But the onclik button say "mapload is not defined".

Do you know why ?

Thanks for your help...

Chris

+1  A: 

mapload() is only defined within initialize(). When your onclick handler tries to call it, it doesn't exist any more. To solve your problem, a quick&dirty solution is to replace all occurrences of mapload with window.mapload. So write

        window.mapload = function (myfile) {
                jQuery.get("trace_" + myfile + ".xml", {}, function(data) {
                    // some actions...
                });
        }

and

<input type="button" value="Hunt Mesa" onclick="window.mapload('hunt')" />
MvanGeest
OK MvanGeest... so how can I call "mapload" from the onclick button ?
Chris
I added the solution.
MvanGeest
That works ;-) Thanks
Chris
Can you accept the answer (that will be possible in 8 minutes)? No thanks, I had to read a good JS book before I could avoid such problems.
MvanGeest