2016-07-31 64 views
1

我想提交表單,但在提交之前我想從模態形式取值。實際要求是,我必須使用複選框選擇多行,然後我想更新數據庫值。我想提交一個表單,但在提交之前我想從模態形式取值

// <!-- 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>

+1

歡迎SO!你可以嘗試添加一個'button'而不是'input [type = submit]',點擊這個按鈕,驗證表單,顯示模式並獲取值。然後點擊模式上的按鈕,提交表格。 – Rajesh

+0

如果您想使用複選框而不是複選框,上面的html會顯示選擇標籤,而不是複選框。 –

+0

另外,將'onClick =「action/changeLeadStage()」'改爲'onClick =「changeLeadStage();''' –

回答

0

嘗試一些事情是這樣的:

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

現在按一下按鈕:

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

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

請檢查下面的代碼片段。根據您的要求,我已對您的代碼進行了更改。

function ChangeLeadStage() { 
 
    if (confirm("Are you sure want to UPDATE lead ?")) { 
 
    var leadStageName = $("select[name='leadStageName']").val(); 
 
    alert(leadStageName); 
 
    return true; 
 
    }else{ 
 
    return false; 
 
    } 
 
}
<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>

相關問題