jquery - Google places autocomplete & Blur problems -
i have form implements google places autocomplete , populate other text fields.
<script type="text/javascript"> $(document).ready(function(){ $('.noentersubmit').keypress(function(e){ if ( e.which == 13 ) return false; }); var updateaddress = { autocomplete: new google.maps.places.autocomplete($("#subscription_address")[0], {types: ['geocode']}), event: function(){ var self = this; google.maps.event.addlistener(self.autocomplete, 'place_changed', function() { var place = self.autocomplete.getplace(), address = place.address_components, streetaddress = '', suburb = '', state = '', zip = '', country = ''; (var = 0; < address.length; i++) { var addresstype = address[i].types[0]; if (addresstype == 'subpremise') { streetaddress += address[i].long_name + '/'; } if (addresstype == 'street_number') { streetaddress += address[i].long_name + ' '; } if (address[i].types[0] == 'route') { streetaddress += address[i].long_name; } if (addresstype == 'locality') { suburb = address[i].long_name; } if (addresstype == 'administrative_area_level_1') { state = address[i].long_name; } if (addresstype == 'postal_code') { zip = address[i].long_name; } if (addresstype == 'country') { country = address[i].long_name; } } // update textboxes settimeout(function(){$('#subscription_address').val(streetaddress).blur(function(e){ this.value = this.streetaddress; });},50); $('#subscription_city').val(suburb); $('#subscription_state').val(state); $('#subscription_zip').val(zip); $('#subscription_country').val(country); }); } }; updateaddress.event(); }); </script> </head> <input class="noentersubmit input-large" name="subscription[address]" id="subscription_address" type="text">
i blocking form submitting on enter keypress. when user enter keypress focus off of text field #subscription_address reset , google places api shows "undefined" value #subscription_address.
currently tab keypress , mouse selection blur event work expected populate other fields , retain streetaddress in #subscription_address field.
using jquery how allow user select autocomplete result using enter keypress focus off text field , retain selected value?
// update textboxes settimeout(function(){$('#subscription_address').val(streetaddress).blur(function(e){ this.value = streetaddress; });},50);
i needed remove this.streetaddress after blur function. had different context when in dom of dropdown.
Comments
Post a Comment