phdphd Posted October 28, 2021 Share Posted October 28, 2021 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! Quote Link to comment https://forums.phpfreaks.com/topic/314132-passing-the-right-series-of-arguments/ Share on other sites More sharing options...
kicken Posted October 28, 2021 Share Posted October 28, 2021 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. 1 Quote Link to comment https://forums.phpfreaks.com/topic/314132-passing-the-right-series-of-arguments/#findComment-1591514 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.