Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9138427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:15:18+00:00 2026-06-17T09:15:18+00:00

I want to implement feature in my TextBox where user will type some address

  • 0

I want to implement feature in my TextBox where user will type some address and from Google API returns address from that user will select the correct address. And He will select the address my Street, Zip, Country, City all will automatically fill.

I am trying this but not get success ( Small part of my aspx page )

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&libraries=places"></script>


<script type="text/javascript">

   var placeSearch,autocomplete;
   var component_form = {
   'route': 'short_name',
    'route': 'long_name',
    'locality': 'long_name',
    'administrative_area_level_1': 'short_name',
    'country': 'long_name',
    'postal_code': 'postal_code'
  };

  function initialize() {
    autocomplete = new google.maps.places.Autocomplete(document.getElementById('autocomplete'), { types: [ 'geocode' ] });
    google.maps.event.addListener(autocomplete, 'place_changed', function() {
      fillInAddress();
    });
  }

  function fillInAddress() {
    var place = autocomplete.getPlace();

    for (var component in component_form) {
      document.getElementById(component).value = "";
      document.getElementById(component).disabled = false;
    }

    for (var j = 0; j < place.address_components.length; j++) {
      var att = place.address_components[j].types[0];
      if (component_form[att]) {
        var val = place.address_components[j][component_form[att]];
        document.getElementById(att).value = val;
      }
    }
  }

  function geolocate() {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function(position) {
        var geolocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
        autocomplete.setBounds(new google.maps.LatLngBounds(geolocation, geolocation));
      });
    }
  }
</script>

And my .aspx page is like this

 <div onload="initialize();">

<asp:UpdatePanel ID="UpdatePanelTabContainer" runat="server">
      <ContentTemplate>
       <table width="100%">
         <tr>
           <td>
               street
           </td>
            <td>
              <asp:TextBox ID="txtPickupStreet" runat="server" MaxLength="100" Width="162px" placeholder="Enter your address" AutoPostBack="true"  onFocus="javascript:geolocate()"></asp:TextBox>
           </td>
      </tr>
        <tr>
            <td>
                Postal Code
            </td>
             <td>
                <asp:TextBox ID="txtPickupPC" runat="server" MaxLength="11" Width="90px" />
             </td>
        </tr>

            </table>
    </ContentTemplate>
            </asp:UpdatePanel>

Here the user will type in street TextBox He will get relative result and select after that all TextBox will be fill .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:15:19+00:00Added an answer on June 17, 2026 at 9:15 am

    Ok there are a few problems with your code.

    I have made a working demo for you.

    I did use jQuery for my additions, but I’m sure you can replace that if you aren’t using jQuery.

    component_form object is wrong
    it should look like this

    var component_form = {
    'txtPickupUnitNumber': 'subpremise',
    'txtPickupStreetNumber': 'street_number',
    'txtPickupStreetName': 'route',
    'txtPickupSuburb': 'locality',
    'txtPickupPC': 'postal_code',
    'txtPickupState': 'administrative_area_level_1',
    'txtPickupCountry': 'country'
    

    };

    The array key is the id of the textbox and the value is the name of the google places result address_component type.

    The geolocate function doesn’t do anything useful
    You are setting the autocomplete search bounds to one lat/lng coord. A bounds should be a collection of lat/lngs. If you are displaying a map on the same page as this form you could do as follows.

    function geolocate() {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(function(position) {
                // set the map to the user locations
                map.setCenter(new google.maps.LatLng(position.coords.latitude,position.coords.longitude));
                // use the viewport as the search bounds
                autocomplete.setBounds(map.getBounds()));
          });
        }
    }
    

    The fillInAddress function will need to be changed to deal with the new component_form array.

    function fillInAddress() {
        var place = autocomplete.getPlace();
        // if you use jQuery then you can delete this and just set the attr to true in the fillFormInput function
        for (var component in component_form) {
            document.getElementById(component).value = "";
            document.getElementById(component).disabled = false;
        }
    
        for (var j = 0; j < place.address_components.length; j++) {
            var att = place.address_components[j].types[0];
            fillFormInput(att, place.address_components[j].long_name);
        }
    }
    
    // This new function searchs for the textbox that corresponds to the address_component type name
    function fillFormInput(att, val) {
        for (var c in component_form) {
            if (component_form[c] === att) {
                $('#'+c).val(val);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement a feature that will import contacts of a user from
I want to implement a feature that if a user is navigating away from
I want to implement this example http://api.geoext.org/1.1/examples/feature-grid.html made of geoext and openlayers, that feature
We want to implement a sitemap.xml feature in out CMS system. There is some
I want to implement chat feature in my android application,in this feature one user
I have an app in which i want to implement a feature where user
I want to implement a feature where user can add new attributes to his
I want to implement a backup feature in the app I'm working on, that
i've a question for a feature, i want to implement. I know some applications,
I want to implement a search feature in an iPhone app. Basically, the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.