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

125
Vistas
javascript/jquery solo afecta el primer elemento

Tengo este código html para un formulario de búsqueda y me gustaría usar jquery para editar la URL para

 let searchform, searchurl, i; searchurl = window.location.href; searchform = document.querySelector("form.dgwt-wcas-search-form"); searchform.action = searchform.action + "index.php";
 <form class="dgwt-wcas-search-form" role="search" action="https://www.myurl.com/" method="get"> <div class="dgwt-wcas-sf-wrapp"> <label class="screen-reader-text" for="dgwt-wcas-search-input-3">Products search</label> <input id="dgwt-wcas-search-input-3" type="search" class="dgwt-wcas-search-input" name="s" value="" placeholder="Search for products..." autocomplete="off"> <div class="dgwt-wcas-preloader" style="right: 81.2812px;"></div> <button type="submit" aria-label="Search" class="dgwt-wcas-search-submit">Search</button> <input type="hidden" name="post_type" value="product"> <input type="hidden" name="dgwt_wcas" value="1"> </div> </form> <form class="dgwt-wcas-search-form" role="search" action="https://www.myurl.com/" method="get"> <div class="dgwt-wcas-sf-wrapp"> <label class="screen-reader-text" for="dgwt-wcas-search-input-3">Products search</label> <input id="dgwt-wcas-search-input-3" type="search" class="dgwt-wcas-search-input" name="s" value="" placeholder="Search for products..." autocomplete="off"> <div class="dgwt-wcas-preloader" style="right: 81.2812px;"></div> <button type="submit" aria-label="Search" class="dgwt-wcas-search-submit">Search</button> <input type="hidden" name="post_type" value="product"> <input type="hidden" name="dgwt_wcas" value="1"> </div> </form>

El script solo cambia la primera URL en el cuadro de búsqueda a https://www.myurl.com/index.php pero el segundo cuadro de búsqueda no hará que se ejecute el script.

Quisiera dos formularios de búsqueda para cambiar la url de https://www.myurl.com/ a https://www.myurl.com/index.php

Cualquier ayuda sería muy apreciada.

Gracias

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Debido a que está utilizando una función de documento incorrecta para consultar, debería haber utilizado "querySelectorAll" en lugar de "querySelector" para que devuelva todos los elementos que coincidan con la consulta.

Después de eso, deberá recorrer la matriz de formularios y establecer una acción para cada formulario tal como lo está haciendo.

about 4 years ago · Juan Pablo Isaza Denunciar

0

 let searchform, searchurl, i; searchurl = window.location.href; searchform = document.querySelector("form.dgwt-wcas-search-form"); searchform.action = searchform.action + "index.php";
 <form class="dgwt-wcas-search-form" role="search" action="https://www.myurl.com/" method="get"> <div class="dgwt-wcas-sf-wrapp"> <label class="screen-reader-text" for="dgwt-wcas-search-input-3">Products search</label> <input id="dgwt-wcas-search-input-3" type="search" class="dgwt-wcas-search-input" name="s" value="" placeholder="Search for products..." autocomplete="off"> <div class="dgwt-wcas-preloader" style="right: 81.2812px;"></div> <button type="submit" aria-label="Search" class="dgwt-wcas-search-submit">Search</button> <input type="hidden" name="post_type" value="product"> <input type="hidden" name="dgwt_wcas" value="1"> </div> </form> <form class="dgwt-wcas-search-form" role="search" action="https://www.myurl.com/" method="get"> <div class="dgwt-wcas-sf-wrapp"> <label class="screen-reader-text" for="dgwt-wcas-search-input-3">Products search</label> <input id="dgwt-wcas-search-input-3" type="search" class="dgwt-wcas-search-input" name="s" value="" placeholder="Search for products..." autocomplete="off"> <div class="dgwt-wcas-preloader" style="right: 81.2812px;"></div> <button type="submit" aria-label="Search" class="dgwt-wcas-search-submit">Search</button> <input type="hidden" name="post_type" value="product"> <input type="hidden" name="dgwt_wcas" value="1"> </div> </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