简体   繁体   中英

Javascript: submit form, set value, disable button

My form has two submit buttons and I need to know which was used to submit the form. I'd like submission of the form to be disabled once it has been submitted in order to avoid double-submissions, and I'd like to use inline Javascript for that.

I can submit the form and disable a button, but the value of the button is not set since it has been disabled and I need that value to be set so I know which button was used to submit the form.

The submit button has id="submit_button" and I'm using this on the form tag:

onsubmit="submit_button.disabled = true; return true;"
  1. Once you submit a form it cannot be submitted again without reloading the page.
  2. To determine which button was used to submit the form, assign a name to the button, ie. <input type="submit" name="button1" value="Click me!"> . In the postback variable button1 will now only be set if this button was used.
  3. The proper way to prevent double submissions is to, after processing the postback, redirect with a 303 See Other to another page, or possibly even the same page, as it will be reprocessed with a GET instead of POST as method. This way it is literally impossible to double-submit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM