question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I know which button is being clicked

See original GitHub issue

i 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:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
SNikhillcommented, Dec 28, 2020

Sorry, I forgot to save the file. Check the link again.

1reaction
SNikhillcommented, Dec 28, 2020

Hey @hungdev, Yes, I get what you want. I have updated the example to better suit your use case. See it Here.

Regards SNikhill

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found