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

68
Visualizações
As a selection the option present in the drop-down menu to the value we get from the parameter we pass in the URL

I have a URL with a parameter, as shown below.

http://example.html?name=Sport

To retrieve the parameter I use the following lines of code:

let url_string = window.location.href;
let url2 = new URL(url_string);
let name_url = url2.searchParams.get("name");

And so far there are no problems.

I want this parameter present in the url to be used as an option for the select, therefore already pre-set to the value that corresponds to the parameter we pass in the URL (in our case on Sport).

I tried to search on the internet but the examples I found are shown in jQuery but I only need it in Javascript.

Can anyone help me to do this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Assign name_url to the .value property of the select.

let url_string = window.location.href;
let url2 = new URL(url_string);
let name_url = url2.searchParams.get("name");
document.getElementById("your-select").value = name_url;

Replace your-select with the ID of the <select> that you want to preset.

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