1. Disable Submit button after click using JavaScript.
- <html xmlns="http://www.w3.org/1999/xhtml">
-
- <head>
- <title></title>
- </head>
-
- <body>
- <form> <input type="button" id="btn" value="Button" /> <input type="submit" id="btnSubmit" value="Submit" />
- <script type="text/javascript">
- window.onbeforeunload = function()
- {
- var inputs = document.getElementsByTagName("INPUT");
- for (var i = 0; i < inputs.length; i++)
- {
- if (inputs[i].type == "button" || inputs[i].type == "submit")
- {
- inputs[i].disabled = true;
- }
- }
- };
- </script>
- </form>
- </body>
-
- </html>
2. Disable Submit button after click using jQuery.
- <html xmlns="http://www.w3.org/1999/xhtml">
-
- <head>
- <title></title>
- </head>
-
- <body>
- <form> <input type="button" id="btn" value="Button" /> <input type="submit" id="btnSubmit" value="Submit" />
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
- <script type="text/javascript">
- $(window).on('beforeunload', function()
- {
- $("input[type=submit], input[type=button]").prop("disabled", "disabled");
- });
- </script>
- </form>
- </body>
-
- </html>