Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

46
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!