模态中的提交按钮无法打开另一个模态

时间:2017-09-25 02:42:42

标签: javascript php html

这是我的第一个模态的HTML代码。提交按钮无法打开另一个模态。

<div class="modal fade" id="newModal">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
               <div class="modal-header">
                    <h5 class="modal-title">New record</h5>
                    <button type="button" class="close" data-dismiss="modal" 
                       aria-label="Close">
                      <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                  <div class="modal-body">
                    <div class="form-group">
                        <input type="text" class="form-control" name="name" 
                           placeholder="Input name of client">
                    </div>
                  </div>
                   <div class="modal-footer">
                    <button type="submit" onclick="submitForm()" class="btn 
                     btn-primary">Submit</button>
                <button type="button" class="btn btn-secondary" data-
           dismiss="modal">Close</button>
                </div>
            </div>
        </div>
      </div>

当您单击第一个模式上的提交按钮时,这是第二个模式的HTML代码。

       <div class="modal fade" id="confirmationModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <form action="php/insert_client.php" method="post">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">Confirmation</h4>
                </div>
                <div class="modal-body">
                 Are you sure you want to add this client?
             </div>
             <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                <button type="submit" class="btn btn-primary" onclick="validateForm()">Save</button>
            </div>
        </form>
    </div>  
</div>

这是newModal和confirmationModal

的javascript
  function submitForm() {
      document.getElementById("newModal").submit();
   }

  function validateForm(e) {
        $("#confirmationModal").modal("show");
  }

1 个答案:

答案 0 :(得分:0)

根据您显示的JS代码,需要调用此函数才能显示第二个模态:

function validateForm(e) {
  $("#confirmationModal").modal("show");
}

现在,在点击第二个模态的保存按钮之前,它不会被调用。