I'm developing a webpage and I would just like to make something more user friendly. I have a functional Google Maps api v3 and an address search bar. Currently, I have to use the mouse to select search to initialize the geocoding function. How can I make the map return a placemark by hitting the enter button on my keyboard and by clicking the search button? I just want to make it as user-friendly as possible.
Here is the javascript and div, respectively, I created for the address bar:
var geocoder;
function initialize() {
geocoder = new google.maps.Geocoder ();
function codeAddress () {
var address = document.getElementById ("address").value;
geocoder.geocode ( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results [0].geometry.location);
marker.setPosition(results [0].geometry.location);
map.setZoom(14);
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
function initialize() {
document.getElementById("address").focus(); }
function setFocusOnSearch() {
document.getElementById("search").focus(); }
function codeAddress() {
document.getElementById("address").focus(); }
<body onload="initialize()">
<div id="geocoder">
<input id="address" type="textbox" value="" "onblur="setFocusOnSearch()">
<input id="search" type="button" value="Search" onclick="codeAddress()">
</div>
</body>
Thank you in advance for your help