Why doesn't my form post when I disable the submit button to prevent double clicking?

后端 未结 10 1262
广开言路
广开言路 2020-12-31 19:06

Like every other web developer on the planet, I have an issue with users double clicking the submit button on my forms. My understanding is that the conventional way to han

10条回答
  •  一整个雨季
    2020-12-31 19:49

    Make sure that your javascript function returns true (or a value that would evaluate to boolean true), otherwise the form won't get submitted.

    function btn_click()
    var chk = document.getElementById("chk");
        if(chk.checked)
        {
                var btn = document.getElementById("btn");
                btn.disabled = true;
                return true;   //this enables the controls action to propagate
        }
        else    return false;  //this prevents it from propagating
    }
    

提交回复
热议问题