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

48
Vistas
Use dropdown selection in URL

I'm following the answer here to use the selection from a dropdown in a URL. I am using asp.net core, using:

asp-page="/Page" asp-page-handler="Action"

To do the redirect

The script below (from the link above) works great, except if you select an item from the dropdown then select a different one (and on and on), it appends both to the URL.

<script>
$("[name=selectedAnalyst]").on("change", function () {
    var analystId = $(this).val();
    var accept = $(this).closest('td').next().find("a")[0];
    var oldUrl = accept.href;
    var newUrl = oldUrl + "&analystid=" + analystId;
    $(accept).attr("href", newUrl);
})

I tried scrubbing the parameter in question (using params.delete) but it's not working:

<script>
$("[name=selectedAnalyst]").on("change", function () {
    var analystId = $(this).val();
    var accept = $(this).closest('td').next().find("a")[0];
    var oldUrl = accept.href;
    let params = new URLSearchParams(oldUrl.search);

    params.delete('analystid')
    var newUrl = oldUrl + "&analystid=" + analystId;

    $(accept).attr("href", newUrl);
})

Is there a way to get the above script to work how I envision, or a better way to do this?

Thank you

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

0

it seems that

let params = new URLSearchParams(oldUrl.search);

    params.delete('analystid')

does not work I tried with the codes and it could work

<script>
        $("[name=selectedAnalyst]").on("change", function () {
            var analystId = $(this).val();
            var accept = $(this).closest('td').next().find("a")[0];
            var oldUrl = accept.href;
            var a = oldUrl.indexOf("analystid");
            console.log(a);
            if (a == -1)
            {
                var newUrl = oldUrl + "&analystid=" + analystId;
            }
            else
            {
                var newUrl= oldUrl.substring(0, oldUrl.length - 1) + analystId;
            }          
            
            console.log(newUrl);
            console.log(oldUrl);           
            $(accept).attr("href", newUrl);
        })
    </script>
about 4 years ago · Juan Pablo Isaza Denunciar

0

Building on what Ruikai Feng posted I think this is working:

$("[name=selectedAnalyst]").on("change", function () {
var analystId  = $(this).val();
var accept = $(this).closest('td').next().find("a")[0];
var oldUrl = accept.href;
var a = oldUrl.indexOf("analystId ");
if (a == -1) {
    var newUrl = oldUrl + "&analystId =" + analystId ;
}
else {
    var newUrl = oldUrl.substring(0, a - 1) + "&analystId =" + analystId;
}

$(accept).attr("href", newUrl);
})
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