javascript - how to get google places autocomplete to work if the textbox is initially hidden and should be shown only after a postback -
i've got 2 textboxes need use google places autocomplete. these textboxes contained in panel hidden on page load. there list of options select, , once user input obtained, hidden panel should shown. i've tried both
panel.visible = false;
and
panel.style["display"] = "none"; panel.style["visibility"] = "hidden";
but neither work. once panel hidden autocomplete textboxes stop working. cannot show panel initially. there work around this? can trigger autocomplete after specific postback? or other way? here's javascript i'm using autocomplete
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script> <script type="text/javascript"> var defaultbounds = new google.maps.latlngbounds( new google.maps.latlng(7.623887, 68.994141), new google.maps.latlng(37.020098, 97.470703)); var input1 = document.getelementbyid('ctl00_reportcontentplaceholder_txtlocality1'); var input2 = document.getelementbyid('ctl00_reportcontentplaceholder_txtlocality2'); var options = { bounds: defaultbounds, types: ['geocode'], componentrestrictions: { country: "in" } }; autocomplete1 = new google.maps.places.autocomplete(input1, options); autocomplete2 = new google.maps.places.autocomplete(input2, options); </script>
i solved problem... found answer here : https://stackoverflow.com/a/8851767/972821
i kinda realized had reinitialize javascript after postback...but wasnt sure how done... aristos. here's modified code :
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script> <script type="text/javascript"> var prm = sys.webforms.pagerequestmanager.getinstance(); prm.add_initializerequest(initializerequest); prm.add_endrequest(endrequest); function initializerequest(sender, args) { } // fires after partial update of updatepanel function endrequest(sender, args) { initialize(); } function initialize() { var defaultbounds = new google.maps.latlngbounds( new google.maps.latlng(7.623887, 68.994141), new google.maps.latlng(37.020098, 97.470703)); var input1 = document.getelementbyid('ctl00_reportcontentplaceholder_txtlocality'); var input2 = document.getelementbyid('ctl00_reportcontentplaceholder_txtdroplocality'); var options = { bounds: defaultbounds, types: ['geocode'], componentrestrictions: { country: "in" } }; autocomplete1 = new google.maps.places.autocomplete(input1, options); autocomplete2 = new google.maps.places.autocomplete(input2, options); } </script>
Comments
Post a Comment