表单不是在chrome上提交,而是在firefox中提交

Form not submiting on chrome but in firefox submitting

本文关键字:提交 firefox chrome 表单      更新时间:2023-09-26

我有一个提交按钮,如下:

保存,继续

And My function in js是:

function checkCreditDebit(buttonValues) {
    //Some validation here
   //Disable Button if once clicked to prevent twice form submission
    document.getElementById('saveandcontinue').disabled = 'disabled';
    document.getElementById('onlysave').disabled = 'disabled';
}

但是当我在firefox中提交表单时,它禁用了"保存&按钮,然后提交表单。但在chrome浏览器中,它禁用按钮,但不提交表单。这有什么问题,请告诉我。

而不是仅仅禁用你的提交按钮(表单也可以提交,如果你在文本框上按enter键),附加一个处理程序到你的表单,将留下一个'类名'给你的表单作为一个标记,表单已经提交,如果用户再次提交表单,处理程序应该检查表单是否已经有类名,然后通过event.preventDefault()防止重复提交。

试试这个:

<form onsubmit="prevent_duplicate(event,this);" action="">
    <input type="text" />
    <input type="submit" />
</form>
<script>
    function prevent_duplicate(event,form)
    {
       if((" "+form.className+" ").indexOf(" submitted ") > -1)
       {
          alert("can't submit more than once!!!");
          event.preventDefault();
       }
       else
       {
           form.classList.add("submitted");
       }
   }
</script>
Demo

    instead of disabling pervent multiple submit by setting a javascript flag example : 
    <form method="post" id="ecomFormBean" name="ecomFormBean" onsubmit="return checkSubmit(this);" >
 <input type="text" />
    <input type="submit" />
</form>
    <script>
    var formSubmitted = false;
    function checkSubmit(f){
        if (formSubmitted) {
          alert('Please be patient. Your order may take 10 - 15 seconds to process. Thank you!');
          return false;
        }
        else return formSubmitted = true;
    }
    </script>

Chrome运行javascript非常快。所以它可能是你的checkCreditDebit(buttonValues)函数,这是禁用提交按钮执行之前,你的php脚本提交表单。

我建议你在调用javascript函数之前调用setTimeOut函数,以便表单可以被提交。

试试吧