');
$('#HomeOfficeWrapper').append('');
//When the document first loads, load the first address value.
$(document).ready(function(){ $('#locations_selector').change(); });
//Whenever the selector is changed for locations
$('#locations_selector').change(function(){
//Collect all of the data that we have on the option fields.
var attributes = getAttributes($("#locations_selector option:selected").first());
//Iterate each one of those defined values looking for a dial with that name.
for (const attr in attributes){
//Iterate each one of the dials on the page to see if it's one of them.
$('.FormLabel').each(function(){
//Check if the field names match.
if($(this).text().toLowerCase().replace('*', '').replace(' ', '_') == attr){
//If we found a match, set the value of this dial.
$(this).parent().parent().find('input').first().val(attributes[attr]);
$(this).parent().parent().find('select').first().val(attributes[attr]);
console.log($("#locations_selector option:selected").text());
updateAddressName($("#locations_selector option:selected").text());
}
});
}
});
//Convert an elements attributes to an array to iterate.
function getAttributes ( $node ) {
var attrs = [];
$.each( $node[0].attributes, function ( index, attribute ) {
attrs[attribute.name] = attribute.value;
} );
return attrs;
}