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

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

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 Relatório

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 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