在jquery对话框中提交表单不起作用

时间:2017-04-10 12:27:43

标签: javascript jquery html forms

在以下代码中,对话框的两个按钮都用于提交表单。但是,当点击对话框中的按钮时,它不会提交。如果用户选择是,我们需要将值发送到发布页面。请帮我解决一下这个。

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" name="edit_billto" id="edit_billto">
  <input type="hidden" name="option" value="com_phpshop" />
  <input type="hidden" name="page" value="<?php echo $next_page; ?>" />
  <input type="hidden" name="next_page" value="<?php echo $next_page; ?>" />
  <input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>" />
<input type="hidden" name="autoship_flag" id="autoship_flag" value="0">
        <input type="submit" id="bill_sumbit" class="button" name="submit" value="<? echo _E_SAVE ?>"  <? echo $submit; ?> />
</form>

Jquery部分

<div id ="alert" style="display:none"> <p> This address is used in autoship. 
    You need to change the address in autoship too? 
    </p></div>
        <script>
          $(document).ready(function() { 
              $("#alert").dialog({autoOpen: false,
                  modal: true,  
                  buttons: {
                    No : function(){
                    isconfirm = true; 
                    //$("form[name='edit billto']").unbind('submit');
                    $("#edit_billto").submit();
                    $(this).dialog("close");

                    //$("form[name='edit billto']").unbind('submit').submit();
                    }, 
                          Yes: save_info
                    },
                  resizable: true,
                  height: "auto",
                  width: "auto",
                  closeOnEscape: false,
                  title: "Autoship Update"

                    });

            });
            var isconfirm = false; 
            $( "form[name='edit_billto']" ).submit(function(e) {
            //alert(isconfirm);
            if(isconfirm === true){
            return true;
            }

               if(isconfirm === false){

                  e.preventDefault();


                    $( "#alert" ).dialog( "open" );
              }             
            });

     function save_info(){   
              isconfirm = true;       
              $("#autoship_flag").val("1");
              $("form[name='edit_billto']").unbind('submit');
              $("form[name='edit_billto']").submit();          
            }       

            </script>

1 个答案:

答案 0 :(得分:0)

不确定原因,您.submit()无效,但您可以尝试.trigger('click')

这样的事情应该有效:

No : function(){
    $("form[name='edit_billto']").off('submit');
    $("#bill_sumbit").trigger('click');
}