单击使用PHP打开模式的锚点标记时,获取模式上的ID [英] Get the id on modal when click on anchor tag for open modal using php
问题描述
我在点击锚标记时打开了一个模式,并使用javascript在输入隐藏字段中传递id值,并且该隐藏字段中显示了值
I have a modal open on click anchor tag and passing the id value in input hidden field using javascript and value is show in this hidden field
<a href="#modal2" data-toggle="modal" data-id="<?php echo $CRow['id'];?>"
id="<?php echo $CRow['id'];?>" class="btn-floating
waves-effect waves-light yellow modal-trigger" title="Test"></a>
<div id="modal2" class="modal">
<form action="lst_applicant.php" method="post" enctype="multipart/form-data">
<div class="modal-content">
<input type="hidden" id="applicantid" name="applicantid" value="" />
<p>Applicant Information</p>
<?php
$applicant_detail=mysql_query("select * from tbl_useraccount where id=".$applicantid);
?>
</div>
<div class="modal-footer">
<button type="submit" name='save' class="btn waves-effect waves-light right modal-close">Save</button>
</div>
</form>
</div>
Here is the code of javascript passing the id value in input hidden field
<script>
$(document).on("click", ".modal-trigger", function () {
var myBookId = $(this).data('id');
$(".modal-content #applicantid").val( myBookId );
});
</script>
问题是,当我在隐藏字段中获取ID但无法获取php变量时.打开模态时如何获取模态上的ID?
Issue is that when I get id in hidden field but cannot get in php variable. how to get id on modal when opening a modal?
当我单击锚标签以打开模态时,然后在模态上有一个输入隐藏字段,在此隐藏字段中,使用javascript显示每个锚标签的id值,我希望当此隐藏字段获取id值时,如何获得PHP变量?我正在使用php变量,但无法正常工作
When I click on anchor tag for open a modal then on modal there is one input hidden field, in this hidden field show a id value of each anchor tag using javascript, I want that when this hidden field get id value so how to get in php variable? I am getting in php variable but it is not working
推荐答案
您可以实现这样的数据,只需在锚模态数据
You can achieve data like this, you just have to provide the details in the anchor modal data
data-id =<?php echo $ CRow ['id'];?>"
和名称 data-name =<?php echo $ CRow['name'];?>"
等
$(document).on("click", ".modal-trigger", function () {
var myBookId = $(this).data('id');
var name = $(this).data('name');
var email = $(this).data('email');
$(".modal-content #applicantid").val( myBookId );
$("#appli_name").val(name);
$("#appli_email").val(email);
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<a href="#modal2" data-toggle="modal" data-id="23" data-name="John" data-email="john@gmail.com" class="btn-floating waves-effect waves-light yellow modal-trigger" title="Test">Click</a>
<div id="modal2" class="modal">
<form>
<div class="modal-content">
<input type="text" id="applicantid" name="applicantid" value="" />
<p>Applicant Information</p>
<input type="text" id="appli_name"><br>
<input type="text" id="appli_email">
</div>
<div class="modal-footer">
<button type="submit" name='save' class="btn waves-effect waves-light right modal-close">Save</button>
</div>
</form>
</div>
这篇关于单击使用PHP打开模式的锚点标记时,获取模式上的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!