dongyu4908
dongyu4908
2016-07-13 11:03

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

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 :)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • duanshang7007 duanshang7007 5年前

    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;
            }
        });
    
    点赞 评论 复制链接分享
  • doushi3189 doushi3189 5年前

    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>
    
    点赞 评论 复制链接分享
  • dsubq24666 dsubq24666 5年前

    Use

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

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

    document.getElementById("monBttn").disabled = "Please wait..."
    
    点赞 评论 复制链接分享

相关推荐