簡體   English   中英

從彈出模式中選擇單選值,而無需重新加載頁面

[英]select radio value from popup modal without reloading page

我有一個模式彈出窗口。 如果在該模式上單擊,則會彈出一個窗口,並顯示單選按鈕。 如果單擊任何單選按鈕並提交該彈出窗口,則選定的單選值應顯示在段落標簽中,而無需重新加載頁面。

我有代碼,但是沒有用。

我的模式按鈕是:(index.php)

<div id="dvPassport1">
            <div class="col-md-6">
        <label>Select Loyalty Membership</label><br>
        <a class="showModal btn btn-primary btn-xs" data-queryid="q11" > View Loyalty Membership</a>
        </div>
        <div class="col-md-6">
        <label>Employee IDs</label>
        <p></p>
        </div>
         </div>

現在,如果單擊“查看會員資格”按鈕,則會打開一個彈出窗口(下面的代碼)(index.php):

<!-- popup modal-->
<div id="id01" class="modal">

 <form class="modal-content animate" action="" method="post" autocomplete="off">
<div class="imgcontainer">
  <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">&times;</span>

</div>

<div class="container">
     <div class="modalContent"></div>

</div>
</form>
</div>
<script>
// Get the modal1
jQuery(document).ready(function($){
var modal = $("#id01");
$("a.showModal").on("click", function(){
    modal.fadeIn();
    var id = $(this).attr("data-queryid");
    var modalServiceUrl = "showstate.php?queryid7="+id;
    modal.find(".modalContent").load(modalServiceUrl);
});
});
// When the user clicks anywhere outside of the modal1, close it
window.onclick = function(event) {

if (event.target == modal1) {
    modal1.style.display = "none";
}
}
</script>
<!-- end popup modal -->

腳本是 (index.php)

<script>
$(document).ready(function(){
$('#btnGetValue').click(function() {
    var selValue = $('input[name=rbnNumber]:checked').val(); 
    $('p').html('<br/>Selected Radio Button Value is : <b>' + selValue + '</b>');
});
});

</script>

最重要的是,代碼在index.php中

showstate.php是:

<?php
if(isset($_GET['queryid7'])){

$queryid7 = $_GET['queryid7'];
echo"<div align='center' style='height:660px; overflow:auto;'  class='w3l-table-info'><h2>Select your Loyalty membership</h2><table id='table'><thead>
    <tr><th>&nbsp;</th>";
 $query12=mysql_query("select * from loyalty_group ORDER BY id") or die (mysql_error());
while($row12=mysql_fetch_array($query12))
        {
            $group_name1=$row12['group_name'];
            $id11=$row12['id'];
echo"<th><input type='radio' id='rbnNumber' name='rbnNumber' value='$id11'/>".$group_name1.'</th>';

        }
echo"<th>&nbsp;</th></tr></thead><tbody>";
echo"</tbody>
<tr><td>&nbsp;</td><td><br><button type='submit' id='btnGetValue' class='btn btn-primary'>Select</button></td></tr>

 </table></div>";
 ?>

現在,如果有任何單選按鈕選擇單擊選擇按鈕,則value ='$ id11'的值應顯示在段落tag(p) (index.php)中, 而無需重新加載頁面(index.php),並且彈出窗口應該關閉。

您的<button type="submit"></button>發送表單並重新加載當前頁面,因為未指定<form action=.. 您要在此處使用的是<button type="button"></button>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM