How do I change a form's action attribute right after clicking the submit button?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
Or you can modify it from outside the form, with javascript the normal way:
You can do that on javascript side .
When clicked, the JavaScript function ActionDeterminator() determines the alternate action URL. Example code.
You can also set
onSubmit
attribute's value in form tag. You can set its value using Javascript.Something like this:
Remember that
onSubmit
has higher priority than action attribute. So whenever you specifyonSubmit
value, that operation will be performed first and then the form will move to action.HTML5's formaction does not work on old IE browsers. An easy fix, based on some of the responses above, is:
There's a simple way to do this if you only need to support modern browsers: on your submit button, add a
formaction="/alternate/submit/url"
attribute like so:It also works on
<button>
tags.The gotcha is that old versions of IE (<10) and the Android Browser (<4.0) do not support it. So, if you need to support older browsers, then the existing JS answers will probably work better for you.
More info: http://www.wufoo.com/html5/attributes/13-formaction.html
Attach to the submit button
click
event and change theaction
attribute in the event handler.