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

242
Visualizações
How can I trigger click on a button when parameter is in URL (error: click is not a function)

I want JavaScript to click a button when a parameter is in the url (&startCalc=1).

html:

<input name="startCalc" value="Start" type="submit">

javascript:

var parameterExists = url.searchParams.get("startCalc");
if(typeof parameterExists !== 'undefined' && parameterExists == 1) {
    document.getElementsByName('startCalc').click();
}

I get an error: "click is not a function". I want to simulate a click the same way as an user would would do it when clicking on that button...

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

0

Two things you need to change First searching parameter in URL and second when getting button by name you get an array so you need to specify the index of that. Check the code below: DEMO

let url = "https://jsfiddle.net&startCalc=1"; // Suppose you are getting url in here
let urlParams = new URLSearchParams(url);
let parameterExists = urlParams.get('startCalc');

if(typeof parameterExists !== 'undefined' && parameterExists == 1) {
    document.getElementsByName('startCalc')[0].click();
    console.log('button clicked!')
}
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