Created
February 17, 2012 11:27
-
-
Save silverflower/1852811 to your computer and use it in GitHub Desktop.
Prototype.jsで、submitボタンの二重クリックの禁止 ref: http://qiita.com/items/2599
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//submitボタンの二重禁止 | |
//全てのformのsubmitイベントの発生時に、formに含まれるsubmitボタンを無効化する。 | |
window.onload = function() { | |
var forms = document.forms; // 存在するフォームを取得する | |
for (var i = 0; i < forms.length; i++) { | |
var form = forms[i]; | |
Event.observe(form, 'submit', AfterClick); | |
} | |
} | |
var AfterClick = function(event) { | |
var form = event.target; // イベントの発生元であるフォームのオブジェクトを取得 | |
var elements = Form.getInputs(form, 'submit'); // フォームにあるsubmitを全て取得 | |
elements.each ( function(element, idx) { | |
element.disabled = true; // submitを全て無効にする | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment