Created
July 2, 2021 17:21
-
-
Save crismanNoble/4a54fd568a813bc6164dd20cf33baa4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fillCityAndStateFields(localities) { | |
var locality = localities[0]; | |
$('#city').val(locality.city); | |
$('#state').val(locality.state); | |
var $input; | |
if(localities.length > 1) { //possibly create a dropdown if we have multiple cities in the result. | |
var $select = $(document.createElement('select')); | |
for(var i = 0; i < localities.length; i++){ | |
var city = localities[i].city; | |
var $option = $(document.createElement('option')); | |
$option.html(city); | |
$option.attr('value', city); | |
if(i == 0) { | |
$option.attr('selected','selected'); | |
} | |
$select.append($option); | |
$select.attr('id','city'); | |
} | |
$input = $select; | |
} else { | |
var city = localities[0].city; | |
var $text = $(document.createElement('input')); | |
$text.attr('value', city); | |
$text.attr('type','text'); | |
$input = $text; | |
} | |
$('#city-input-wrapper').html($input); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment