Stop multiple submits for a html from

后端 未结 2 489
温柔的废话
温柔的废话 2021-01-29 11:03

So I\'ve google this problem, they all give the same code but it never works. I want to be able to only click on the button once so you can\'t spam click the button sending the

2条回答
  •  忘掉有多难
    2021-01-29 11:24

    If I understood you correctly, you should try the following:

    Instead of using inline javascript, I gave the submit input an id and use this javascript code:

    var form = document.getElementById('sign'),
        submit = document.getElementById('submit');
    
    submit.onclick = function() {
        submit.value='Submitting ..';
        form.submit();
    };
    

    https://jsfiddle.net/5kn2L7m9/3/

    I also removed the .disabled = true because I think that's why the form wasn't submitting at all before. You should maybe do it by adding a class and removing the onclick event listener or check in the javascript if the form has been already sent.

提交回复
热议问题