Javascript onsubmit which button was clicked




















Meteor allows you to utilize any javascript solution to a unit of problem in a straightforward manner. It is not a limitation imposed by Meteor. It is how dom, events and javascript works. The proposed solutions are not very elegant, but they are not ugly hacks either.

Meteor is not a magic wand. But it is one of the six cool vendors pointed out by Gartner. Gartner is the most serious assessor of trends and technologies out there. You will be much happier if you appreciate what you already have and make full use of it. Regardless of the fact, your problem is irrelevant to Meteor and is already provided with a solution that is applicable to your meteor app. It is extremely easy to learn and very powerful.

It will save you many hours of effort with dom handling. Meteor docs for event maps is very easy to follow and has some examples. So is jquery. There is no HTTP request. It is explained at the very beginning of the docs. Furthermore, you are already stopping any http request yourself by doing event. I also suggest you to refactor your code to not use multiple submit buttons and a single event handler. Your apps two different buttons do two distinct things so they should have two distinct events and associated handlers.

If you have actually read meteor docs and the link that sashko has shared with you, you would have solved your problem by now.

Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Can I determine which Submit button was used in javascript? Ask Question. Asked 11 years, 8 months ago. Active 8 months ago. Viewed 32k times. Improve this question. Scott Saunders Scott Saunders It looks like someone went through and down-voted most of the answers without any explanation.

Downvoting without commenting is just cowardly. Looks like someone was bored more than they had a problem with the answers, everyone here has at least a Add a comment. Active Oldest Votes. Here's an unobtrusive approach using jQuery Improve this answer.

Glen Little Glen Little 6, 4 4 gold badges 42 42 silver badges 65 65 bronze badges. One does not need to tie the function call to the form; it also works on the buttons. This question and answer are both over 3 years old now. Today, I would use JQuery and bind events to the buttons. However, this approach still works if you aren't doing much javascript on the page. There was far more reason to use jQuery 3 years ago than there is today.

Thanks for this answer — David Cruz. Christoph Christoph k 36 36 gold badges silver badges bronze badges. Do not assume a button was clicked, it could have been enter being pressed on a text field, check target.

Alas, this doesn't work on Safari, document. See more comparisons here. Catfish Catfish You can grab elements based on their id's and perform operations on them. Will one of those operations tell me whether the button was clicked? Wojciech Dynus Wojciech Dynus 5 5 silver badges 11 11 bronze badges. I haven't evaluated what happens if the user uses the Enter key to submit the form, rather than clicking.

Then you have access to the 'initiator' variable anywhere that might need to do the checking. Hope this helps. How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Form onSubmit determine which submit button was pressed [duplicate] Ask Question. Asked 11 years, 2 months ago. Active 1 year, 2 months ago. Viewed k times. Improve this question. Peter Mortensen 29k 21 21 gold badges 97 97 silver badges bronze badges. McTrafik McTrafik 2, 3 3 gold badges 25 25 silver badges 31 31 bronze badges. I think this is not duplicate, the other question is in jquery context while this one is not, see my answer below.

Agreed, Javascript! NOT a duplicate.. Add a comment. Active Oldest Votes. Improve this answer. Ali Shakiba Ali Shakiba This solution is simple, elegant, and easy to implement; why anyone would prefer Peter Bailey's solution, which is extremely cumbersome and requires jquery which the original question DID NOT specify is beyond me. This won't work if the form was submitted by the user pressing enter — 99 Problems - Syntax ain't one.

How does this work? I can't figure out what is "this. How am I accessing the form from within the button object? Not in the submit event handler itself, no.



0コメント

  • 1000 / 1000