dongyu4908
2016-07-13 11:03
浏览 87
已采纳

单击按钮提交表单并禁用按钮

Please I need your help, I want to disable a button on click and submit my form this is the code

            {{ form_start(form, {'attr': {'id': 'myForm'}}) }}

                    //....... NOT important

                {{ form_rest(form) }}

                <button class="btn-large waves-effect waves-light fullwidth" type="submit" id="monBttn"  onclick="myFunction()" name="action"
                        value="{{ 'registration.submit'|trans({}, 'FOSUserBundle') }}">
                    <i class="material-icons left">save</i>
                    Enregistrer
                </button>
            {{ form_end(form) }}

In my button i called a fuction this is the code

<script>
    function myFunction() {
        buttn = document.getElementById("monBttn");
        document.getElementById("myForm").submit();
        buttn.setAttribute('disabled','disabled');
    }
</script>

my script does not work the button is disabled but it does'nt submit the value Thanks in advance :)

图片转代码服务由CSDN问答提供 功能建议

我需要你的帮助,我想在点击时禁用一个按钮并提交我的表格这是代码

  {{form_start(form,{'attr':{'id':'myForm'}})}} 
 
 // ....... NOT 重要
 
 {{form_rest(form)}} 
 
&lt; button class =“btn-large waves-effect wave-light fullwidth”type =“submit”id =“monBttn”onclick =“myFunction()  “name =”action“
 value =”{{'registration.submit'| trans({},'FOSUserBundle')}}“&gt; 
&lt; i class =”material-icons left“&gt; save&lt;  / i&gt; 
 Enregistrer 
&lt; / button&gt; 
 {{form_end(form)}} 
   
 
 

在我的按钮中,我称之为功能,这是 代码

 &lt; script&gt; 
函数myFunction(){
 buttn = document.getElementById(“monBttn”); 
 document.getElementById(“myForm”)。  submit(); 
 buttn.setAttribute('dis 有能力','禁用'); 
} 
&lt; / script&gt; 
   
 
 

我的脚本不起作用按钮被禁用但它没有提交 值 提前谢谢:)

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • duanshang7007 2016-07-13 11:28
    已采纳

    I have create one demo. It is working fine.

    HTML

    <form>
        <input type="submit" value="submit" id="submit">
    </form>
    

    SCRIPT

    $(function(){
            document.getElementById("submit").onclick = function() {
                this.disabled = true;
            }
        });
    
    打赏 评论
  • dsubq24666 2016-07-13 11:06

    Use

    document.getElementById("monBttn").disabled = true;
    

    and you can also display the "please wait" message.

    document.getElementById("monBttn").disabled = "Please wait..."
    
    打赏 评论
  • doushi3189 2016-07-13 11:16

    Thx guys for the help this is the working script:

    <script>
        function myFunction() {
            document.getElementById("monBttn").disabled = true; 
            document.getElementById("monBttn").innerHTML = "Traitement en cours...";
            document.getElementById("myForm").submit();
        }
    </script>
    
    打赏 评论

相关推荐 更多相似问题