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

178
Visualizações
onchange Submit Form with Page Anchor

Using something like this code is there anyway of passing a html anchor to jump to a particular place in the page when it has been submitted?

onChange="document.form2.submit()"

Im using this code above for a dropdown menu which submits after selection, but i also need it to pass a page anchor.. is this doable?

many thanks

ps The anchor will depend on which dropdown menu was used. There are, for example, around 40 dropdown menus in a page.. so when you get over 20 you have to keep scrolling down to select the next one.. this is why i need the page, after submitting, to jump to the last dropdown used... Hope this makes sense.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Set the action of the form to url#your-hash right before you submit.

function change_url(form, hash) {
  form.setAttribute("action", "https://example.com/#" + hash);
  form.submit();
}

document.querySelectorAll("select").forEach(function(elem) {
  elem.addEventListener("change", function() {
    var hash = this.getAttribute("name");
    var form = this.closest("form")
    change_url(form, hash);
  })
})
<h1>fill the form</h1>
<form action="" method="get" onsubmit="change_url(this); return false">


  <a name="sel1"></a>
  <select name="sel1">
    <option></option>
    <option>sel1</option>
  </select>

  <div style="height:500px"></div>

  <a name="sel2"></a>
  <select name="sel2">
    <option></option>
    <option>sel2</option>
  </select>

  <div style="height:500px"></div>

  <a name="sel3"></a>
  <select name="sel3">
    <option></option>
    <option>sel3</option>
  </select>

  <div style="height:500px"></div>

  <button>submit</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