Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
Hi,

I am getting kind of confused as I was coding a simple input text box that takes in
a zip code, which then displays a google map with its map api.

I initially started out with ajax in mind, but as i was doing it, I found
that i ended up with a javascript function that takes in the zip code from my form.
The function just initializes the map element from the zip code input, where I can just display it on the page.

My text box has an onkeyup parameter that calls the function as below:

C#
function initialize(str) {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map_canvas"));

    var geocoder = new GClientGeocoder();
    geocoder.setBaseCountryCode("us");

    geocoder.getLatLng(
      str,
      function(point) {
        if (point) {
          map.setCenter(point, 13);
          var marker = new GMarker(point);
          map.addOverlay(marker);
        }
      }
    );
  }
}


I'm probably not that strong in my concepts, so what's this document.getElementById part? Is that a javascript thing?

So why do we need ajax then? For cases where javascript is not supported?
Confused.


Brian
Posted

The document.getElementById is a javascript. Ajax is used if you want a service call accessed on your page without leaving that page (no-postback). That ajax (server side coding) call is still handled by javascript(client side coding).

http://www.webdeveloper.com/forum/archive/index.php/t-178422.html[^]
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 15-Apr-11 2:50am    
Correct, a 5.
--SA
document.getElementById is a Javascript thing.

AJAX is a way to communicate with server from client using Javascript.


To read more on AJAX and how it is used, look here: AJAX tutporial[^]
More details here.[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Apr-11 2:50am    
Correct, a 5.
--SA
Sandeep Mewara 15-Apr-11 3:44am    
Thanks SA!
try this Link

Clickhere[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900