Which submit button




















You've got the same name on two different elements. Change the names to "Change" and "Delete" and then determine if either one of them were clicked by applying an event handler on both submits and providing different methods. I'm assuming you're using pure JavaScript, but if you want it to be quick, take a look at jQuery.

What you need is as simple as following what's on w3schools. Since you didn't mention using any framework, this is the cleanest way to do it with straight Javascript. With this code what you're doing is passing the button object itself into the go function. You then have access to all of the button's properties. You don't have to do anything with setTimeout 0 or any other wacky functions.

A click event anywhere in a form will be caught by a form's click handler as long as the element clicked on allows it to propagate.

It will be processed before the form's submit event. 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. This is typically a new tab in the same window as the current document, but may differ depending on the configuration of the user agent. Loads the response into the parent browsing context of the current one.

Loads the response into the top-level browsing context; this is the browsing context that is the topmost ancestor of the current context. So you should be in the habit of expressly specifying which button is the submit button. Keyboard shortcuts, also known as access keys and keyboard equivalents, let the user trigger a button using a key or combination of keys on the keyboard.

In order to avoid conflicts with the user agent's own keyboard shortcuts, different modifier keys are used for access keys than for other shortcuts on the host computer. See accesskey for further details. The problem with the above example is that the user will not know what the access key is!

This is especially true since the modifiers are typically non-standard to avoid conflicts. When building a site, be sure to provide this information in a way that doesn't interfere with the site design for example by providing an easily accessible link that points to information on what the site access keys are.

Notice that each input field must have a name attribute to be submitted. If the name attribute is omitted, the value of the input field will not be sent at all. We just launched W3Schools videos. Get certified by completing a course today! If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:. PHP isset function is used to check if a variable has been set or not.

This can be useful to check the submit button is clicked or not. The isset function will return true or false value. The isset function returns true if variable is set and not null.

The submit event is sent to an element when the user is attempting to submit a form. This happens prior to the actual submission, so we can cancel the submit action by calling. We can trigger the event manually when another element is clicked:,After this code executes, clicks on Trigger the handler will also display the message. In addition, the default submit action on the form will be fired, so the form will be submitted.



0コメント

  • 1000 / 1000