Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
<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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda