Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
<button type="submit"> not working on mobile devices

I have this form which shows the user how far an address is from the city of Silkeborg in Denmark by using Google Maps.

The first input field is address and the second one is zipcode.

The form can be seen here: https://silkeborgkalder.eistrupweb.dk/job-i-silkeborg/

On desktop the form works as it should. However, on mobile devices nothing happens when I fill out the form and hit the submit button "Vis afstand" (Show distance).

When submitted the following Javascript is executed:

function vejviser() {
  var adresse = document.getElementById("adresse");
  var by = document.getElementById("by");
  window.open("https://www.google.com/maps/dir/?api=1&origin=Silkeborg&destination=" + adresse.value + "+" + by.value + "&travelmode=driving")
}
<form id="jobDistanceCalculator">
  <input id="adresse" class="input-felt" type="text" placeholder="Arbejdspladsens adresse" name="adresse" /><br />
  <input id="by" class="input-felt" type="number" placeholder="Arbejdspladsens postnummer" name="postnummer" /><br />
  <button type="submit" class="submit-btn" value="Vis afstand">Vis afstand</button>
</form>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Apart from the error from the gaTracker, it seems you are missing an event listener

window.addEventListener("load", function() {
  document.getElementById("jobDistanceCalculator").addEventListener("load", function(e) {
    e.preventDefault(); // stop submission
    var adresse = document.getElementById("adresse");
    var by = document.getElementById("by");
    window.open("https://www.google.com/maps/dir/?api=1&origin=Silkeborg&destination=" + adresse.value + "+" + by.value + "&travelmode=driving")
  })
})
<form id="jobDistanceCalculator">
  <input id="adresse" class="input-felt" type="text" placeholder="Arbejdspladsens adresse" name="adresse" /><br />
  <input id="by" class="input-felt" type="number" placeholder="Arbejdspladsens postnummer" name="postnummer" /><br />
  <button type="submit" class="submit-btn" value="Vis afstand">Vis afstand</button>
</form>

But why a script?

<form id="jobDistanceCalculator" action="https://www.google.com/maps/dir/">
  <input type="hidden" name="api" value="1" />
  <input type="hidden" name="origin" value="Silkeborg" />
  <input type="hidden" name="travelmode" value="driving" />

  <input name="destination" class="input-felt" type="text" placeholder="Arbejdspladsens adresse og post nummer" /><br />
  <button type="submit" class="submit-btn" value="Vis afstand">Vis afstand</button>
</form>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!