Using Barcode creator for Online Control to generate, create Barcode image in Online applications.

OnBarcode.com/Barcode

JavaScript function. The storeMarker() function does not yet exist in your script, and if you try to click the Save button, you ll get a JavaScript error. Ignore this for now, as you ll create the storeMarker() function in the Saving Data with GXmlHttp section later in the chapter, when you save the form contents to the server.

Using Barcode drawer for VS .NET Control to generate, create 2D image in VS .NET applications.

OnBarcode.com/2D

things like name, action, target, and method, but once you venture beyond these basic four, you may begin to notice inconsistencies. For example, using setAttribute() to define onsubmit works fine in Mozilla-based browsers but not in Microsoft Internet Explorer browsers. For cross-browser compatibility, you need to define onsubmit using a function, as you did in Listing 3-4. For more detailed information regarding DOM and how to use it, check out the DOM section of the W3Schools website at http://www.w3schools.com/dom/.

Using Barcode encoder for BIRT Control to generate, create Barcode image in BIRT applications.

OnBarcode.com/Barcode

Figure 3-6. The info window with an embedded form In Listing 3-4, the latitude and longitude elements of the form have been pre-populated with the latlng.lat() and latlng.lng() values from the GLatLng object passed in to the event listener. This allows you to later save the latitude and longitude coordinates and re-create the marker in the exact position when you retrieve the data from the server. Also, once the information has been saved for the new location, you can use this latitude and longitude to instantly create a marker at the new location, bypassing the need to refresh the web browser to show the newly saved point. If you click again elsewhere on the map, you ll also notice your info window disappears and reappears at the location of the new click. As a restriction of the Google Maps API, you can have only one instance of the info window open at any time. When you click elsewhere on the map, the original info window is destroyed and a brand-new one is created. Be aware that it is not simply moved from place to place. You can demonstrate the destructive effect of creating a new info window yourself by filling in the form (Figure 3-7), and then clicking elsewhere on the map without clicking the Save button. You ll notice that the information you entered in the form disappears (Figure 3-8) because the original info window is destroyed and a new one is created.

CHAPTER 3 INTERACTING WITH THE USER AND THE SERVER

Figure 3-7. Info window with populated form information

Figure 3-8. New info window that has lost the previously supplied information

CHAPTER 3 INTERACTING WITH THE USER AND THE SERVER

Earlier, when you created the info window containing You clicked here! the same thing happened. Each marker had the same content ( You clicked here! ), so it just appeared as though the info window was simply moving around.

If you ve taken some time to review the Google Maps API in Appendix B, you might be wondering why Tip you couldn t use the GMap2.openInfoWindowHtml() method to add the form to the info window. After all, it lets you use an HTML string rather than an HTML DOM element. The short answer is you can. In version 1 of the API, openInfoWindowHtml() required a marker to exist on the map first, whereas openInfoWindow() allowed you to open an info window at a specified point without a marker. We chose to use the openInfoWindow() method here so that you would be able to see how the DOM structure and click actions interact with the info window.