Can we put two JavaScript onclick events in one input type button tag? To call two different functions?
The addEventListener() methodYou can add many event handlers of the same type to one element, i.e two "click" events.
So the answer is - yes you can :) However, I'd recommend to use unobtrusive JavaScript.. mixing js with HTML is just nasty.
The first solution to perform multiple onClick events in React is to include all of your actions inside of a function and then call that single function from the onClick event handler. Let's explore how to do that in a React Component: import React from 'react'; function App() { function greeting() { console.
If you want to call a function when the onclick event happens, you'll just want the function name plus the parameters. Then if your parameters are a variable (which they look like they are), then you won't want quotes around them.
This one works:
<input type="button" value="test" onclick="alert('hey'); alert('ho');" />
And this one too:
function Hey() { alert('hey'); } function Ho() { alert('ho'); }
.
<input type="button" value="test" onclick="Hey(); Ho();" />
So the answer is - yes you can :) However, I'd recommend to use unobtrusive JavaScript.. mixing js with HTML is just nasty.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With