Which submit button was clicked




















Programming is all about solving problems of doing units of work. Correct answers are marked as correct with the green checkmark. Furthermore, other high quality answers have higher rankings which are displayed in the form of number of upvotes right beside the question.

Meteor is not a dom event handler. It is a platform, or arguably a framework. It allows you to write otherwise verbose code in concise units. The template event handlers are very powerful in that regard. 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. Therefore, one can test whether the click target was an input or button tag of the submit type, and save the value of it say, to a data-button attribute on the form for processing in the form's submit handler.

I needed to do this to change a form's action and target attributes, depending upon which submit button is clicked. Name the delete button something else. Perhaps name one SubmitChange and name the other SubmitDelete. I've been dealing with this problem myself. There's no built-in way to tell which button's submitting a form, but it's a feature which might show up in the future. The workaround I use in production is to store the button somewhere for one event loop on click.

The JavaScript could look something like this:. I have a tiny plugin to handle temporarily setting data on an element that looks like this:. 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, 9 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. This label is likely to be something along the lines of "Submit" or "Submit Query. A string indicating the URL to which to submit the data. A string that identifies the encoding method to use when submitting the form data to the server.

There are three permitted values:. This, the default value, sends the form data as a string after URL encoding the text using an algorithm such as encodeURI. Plain text; mostly useful only for debugging, so you can easily see the data that's to be submitted.

If specified, the value of the formenctype attribute overrides the owning form's action attribute. A string indicating the HTTP method to use when submitting the form's data; this value overrides any method attribute given on the owning form. Permitted values are:. A URL is constructed by starting with the URL given by the formaction or action attribute, appending a question mark "?

This is the default value. The form's data is included in the body of the request that is sent to the URL given by the formaction or action attribute using an HTTP post method. This method supports complex data and file attachments. This method is used to indicate that the button closes the dialog with which the input is associated, and does not transmit the form data at all.



0コメント

  • 1000 / 1000