Jump to content

Recommended Posts

Hi All,

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 ?

Thanks!

 

Link to comment
https://forums.phpfreaks.com/topic/314132-passing-the-right-series-of-arguments/
Share on other sites

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.

  • Great Answer 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.