Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use an ajax request and run your JS code after success of this request.</p> <p>You are using jQuery so you can use:</p> <pre><code>$('#yourform-id').on('submit', function(event) { $.ajax('/your/url/here', { type: 'post', data: { zipcode: $('#address').val() } }).done(function() { /* your JS code after successful request goes here */ }); event.stopPropagation(); } </code></pre> <p><strong>EDIT:</strong> You can do this also without the ajax request. But the important thing is to register the <code>.on('submit', function(event) { /* your geocode JS code here */ event.stopPropagation(); }</code> event to your form so the form doesn't get sent.</p> <p>The <code>event.stopPropagation()</code> stops your form from reloading the page and send the form data via HTTP. In earlier jQuery versions you returned <code>false</code> but this is deprecated now.</p> <p>So add this code to the HTML file where your form is too:</p> <pre><code>$(function() { // on ready $('#yourform-id').on('submit', function(event) { var address = document.getElementById('address').value + ', CH'; geocoder.geocode({'address': address}, function(results, status){ if(status == google.maps.GeocoderStatus.OK){ map.setCenter(results[0].geometry.location); var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location, title: 'Sie suchten nach:' + ' ' + address }); } else if(status == google.maps.GeocoderStatus.ZERO_RESULTS){ window.alert = function(){} } else{ alert('An unknown error occured. Refresh the page or contact the IT team! Error: '' + status + '''); } }); event.stopPropagation(); }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload