var checkInt = setInterval(check); function check() { if (window.hasOwnProperty('google')) { google.maps.event.addDomListener(window, 'load', initialize); clearInterval(checkInt); } } function initialize() { var input = document.getElementById('pickup'); var input2 = document.getElementById('dropoff'); new google.maps.places.Autocomplete(input); new google.maps.places.Autocomplete(input2); } $('.datepicker').datepicker(); });