I'm using the Google Places API to list pick up and drop off locations for a transportation service. We have two fields that, when typed in, autosuggest results.
When a a dropdown, #transport-type, is set to the first option, value = 1, then the input field, #pick-up-location, should have 'types' airport added to its results.
JS:
function transport_types() {
if ($('#transport-type').val() == 1) {
var input = document.getElementById('pick-up-location');
var options = { types: ['airport'] };
autocomplete = new google.maps.places.Autocomplete(input, options);
}
if ($('#transport-type').val() == 2) {
var input = document.getElementById('drop-off-location');
var options = { types: ['airport'] };
autocomplete = new google.maps.places.Autocomplete(input, options);
}
google.maps.event.addDomListener(window, 'load', initialize);
}
Dropdown HTML:
<select id="transport-type" name="TransNeeded" required="true" tabindex="101" onChange="transport_types();">
<option value='0' selected='selected'>Where do you want to go?</option>
<option value='1' onfocus="enableGoogle('', true);" id="pick-up-type">Pick-Up Location is an Airport</option>
<option value='2' onfocus="enableGoogle('', true);" id="drop-off-type">Drop-Off Location is an Airport</option>
<option value='3' onfocus="enableGoogle('', true);" id="point-point-type">Point to Point or Charter</option>
</select>
Input HTML:
<input type="text" id="pick-up-location" name="PUFullAddress" tabindex="104" value="Pick-Up Location" required="true"
onblur="if(this.value.length==0) { $('#pick-up-location').attr('value', ''); }"
onkeypress="delay(50);"
onfocus="enableGoogle('PU', false);"
/>
<input id="drop-off-location" name="DOFullAddress" type="text" tabindex="105" value="Drop-Off Location" required="true"
onblur="if(this.value.length==0) { $('#drop-off-location').attr('value', ' '); }"
onkeypress="delay(50);"
onfocus="enableGoogle('DO', false);"
/>
I'm not the most seasoned jQuery programmer, so it could even be an issue of syntax. I appreciate any insight you guys can provide.
Thanks for your time!