我想提交一份表格但在提交之前我想从模态表格中取一个值

时间:2016-07-31 06:17:11

标签: javascript php jquery html forms

我想提交一份表格,但在提交之前,我想从模态表单中获取一个值。实际要求是,我必须使用复选框选择多行,然后我想更新数据库值。

// <!-- JAVASCRIPT ON MODAL FORM SUBMIT -->
function changeLeadStage() {
  if (confirm("Are you sure want to UPDATE lead ?")) {
    document.frmUser.action = './changeleads.php';
    document.frmUser.submit();
  }
}
<!-- BUTTON PRESSED AFTER SELECTING ROWS -->

<input type="button" class="btn btn-sm btn-success warning_1" value="changeLeadStage" onClick="action/changeLeadStage();" />

<!-- MODAL FORM -->
for updating the database after selecting rows i opened a model form and want to take a value from dropdown of form. and after submit i want to change database value.


<div id="myModal" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h4 class="modal-title">Subscribe our Newsletter</h4>
      </div>
      <div class="modal-body">

        <form name="frmUser" action="" method="POST">

          <select name="leadStageName" type="text" style="padding:5px; border-radius:3px;" required />
          <option value="" selected>Select LeadStage</option>
          <option value="LeadStage1">LeadStage1</option>
          <option value="LeadStage2">LeadStage2</option>
          <option value="LeadStage3">LeadStage3</option>
          <option value="LeadStage4">LeadStage4</option>
          <option value="LeadStage5">LeadStage5</option>
          </select>
          <br>
          <br>
          <br>
          <input type="submit" name="changeLeadStage" class="btn btn-sm btn-success warning_1" onClick="action/changeLeadStage();" />
        </form>
      </div>
    </div>
  </div>
</div>

2 个答案:

答案 0 :(得分:0)

尝试这样的事情:

Change the input[type=submit] to input[type=button] 

现在点击按钮:

$('button').click(function(){
var value = $('#id').val();

// submit the form
$('#fomrid').submit();
});

答案 1 :(得分:0)

请查看下面的代码段。我已根据您的要求更改了代码。

&#13;
&#13;
function ChangeLeadStage() {  
  if (confirm("Are you sure want to UPDATE lead ?")) {
    var leadStageName = $("select[name='leadStageName']").val();
    alert(leadStageName);
    return true;
  }else{
    return false;
  }
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- BUTTON PRESSED AFTER SELECTING ROWS -->

<!-- MODAL FORM -->
for updating the database after selecting rows i opened a model form and want to take a value from dropdown of form. and after submit i want to change database value.


<div id="myModal" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
  
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h4 class="modal-title">Subscribe our Newsletter</h4>
      </div>
      <div class="modal-body">

        <form id="frmUser" name="frmUser" action="./changeleads.php" method="post" onsubmit="return ChangeLeadStage();">

          <select name="leadStageName" type="text" style="padding:5px; border-radius:3px;">
          <option value="" selected>Select LeadStage</option>
          <option value="LeadStage1">LeadStage1</option>
          <option value="LeadStage2">LeadStage2</option>
          <option value="LeadStage3">LeadStage3</option>
          <option value="LeadStage4">LeadStage4</option>
          <option value="LeadStage5">LeadStage5</option>
          </select>
          <br>
          <br>
          <br>
          <input type="submit" name="changeLeadStage" class="btn btn-sm btn-success warning_1" />
        </form>
      </div>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;