Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member
    Join Date
    Apr 2005
    Location
    Hatfield, England
    Posts
    855
    Member #
    9790
    Hi,

    This code works and places a marker on the map.

    HTML Code:
    <input type="submit" value="Place Marker" onclick="javascript:
    usePointFromPostcode('<?php print $row->postcode; ?>', placeMarkerAtPoint)" />
    <div id="map" style="width: 100%; height: 300px"></div>
    This code doesn't work

    HTML Code:
    <script type="text/javascript">usePointFromPostcode('<?php print $row->postcode; ?>', placeMarkerAtPoint);</script>
    <div id="map" style="width: 100%; height: 300px"></div>
    Instead it generates this error.
    Error: map is undefined
    Why does one work but the other doesn't?

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    I could be way off, but because in the first example, the page is rendered and displayed, the script knows that there is an element with an id of map (you cannot submit something that is not there).

    However, by the looks of your second example, the code is run outside of any event, meaning the page has not yet created the div you are referring to.

    Edit: so move the javascript below the div line and that "should" do it.

  4. #3
    Senior Member
    Join Date
    Apr 2005
    Location
    Hatfield, England
    Posts
    855
    Member #
    9790
    I thought something similar. I moved the line below the map. I even moved the code to the bottom of my page below the footer. Still no luck.

    I agree that it is probably something to do with the page load order but I can't figure out how to fix it.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:13 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com