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

138
Views
Passing The Right Series Of Arguments

In one HTML page, I have 2 onclick events like this :

onclick="clear_input('button1', 'hello1','world1');"
onclick="clear_input('button2','hello2','world2');"
 

In a JS file I have this :

function clear_input(a, b, c) {

var text = document.getElementById(b);

var button = document.getElementById(a);

…

}

It all works. Now I want to get rid of the inline JS and implement in the JS file an addEventListener that could process any one of the 2 onclick events. How do I pass the right series of arguments ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If it's just two, it's probably not worth effort to create some generic solution. Just add each call individually.

document.getElementById('whatever1').addEventListener('click', function(){
    clear_input('button1', 'hello1', 'world1');
});
document.getElementById('whatever2').addEventListener('click', function(){
    clear_input('button2', 'hello2', 'world2');
});

If you need a more generic solution you'll need to explain more about the situation, like why the arguments are 'button1', 'hello1', 'world1' to start with.

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!