Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda