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

243
Vistas
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 Respuestas
Responde la pregunta

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