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

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

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