How do I know which button is being clicked
See original GitHub issuei have 2 buttons with type=“submit”. How do I know which button is being clicked?
<AvForm onSubmit={onSubmit}>
<AvField name="name" label="Name" required />
<Button type='submit' name='save'>Save </Button>
<Button type='submit' name='next'>Next </Button>
</AvForm>
const onSubmit = (event, errors, values) => {
console.log(event.target.name)
}
i tried to get event.target.name in onSubmit function, but it cannot get button name. thank you
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
How to know which button is clicked - Stack Overflow
This is simple using jQuery: $(':button').click(function() { // reference clicked button via: $(this) var buttonElementId ...
Read more >How to get the ID of the clicked button using JavaScript/jQuery
Given a set of button and the task is to determine the ID of the button when it is clicked using JavaScript and...
Read more >Check if Element was Clicked using JavaScript | bobbyhadz
To check if an element was clicked, add a click event listener to the element, e.g. button.addEventListener('click', function handleClick() {}) .
Read more >Check If a Button Is Clicked in JavaScript - Maker's Aid
To listen to clicks on any button, we can create a generic event listener for the <button> element. We can use the querySelectorAll()...
Read more >Get ID Of Clicked Element In JavaScript - SoftAuthor
One of the ways to get an ID attribute of a clicked element is that you actually attach click events to all the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry, I forgot to save the file. Check the link again.
Hey @hungdev, Yes, I get what you want. I have updated the example to better suit your use case. See it Here.
Regards SNikhill