[英]how to get div id into php variable?
How can I get this id
into a PHP variable after submit a form? 如何在提交表单后将此
id
到PHP变量中? I need to pass the total value to a PHP variable. 我需要将总值传递给PHP变量。 Please help me to solve this problem.
请帮我解决这个问题。
<div class="table-responsive">
<table class="table table-bordered">
<tr>
<th>Total Price</th>
</tr>
<tr>
<td>
<input class="form-control1" type='text' id='txt_totalprice' name='txt_totalprice[]'/>
</td>
</tr>
</table>
</div>
Total: <div id="totalvalue">0</div>
Here is the script 这是脚本
<script type='text/javascript'>
$('#totalvalue').click(function() {
$.post("package.php", {
id: $(this).attr('id')
}, function(response) {
alert(response);
});
});
</script>
You want the value between the div tags, not the ID, correct? 你想要div标签之间的值,而不是ID,是否正确?
Change this: 改变这个:
id: $(this).attr('id')
To this: 对此:
id: $(this).text()
If you want to display the value on the page do this: 如果要在页面上显示值,请执行以下操作:
Create an empty div: 创建一个空div:
<div id="saved-value"></div>
Place it anywhere you want on the page. 将它放在页面上任何您想要的位置。
Then change your jQuery: 然后改变你的jQuery:
}, function(response) {
$('#saved-value').html(response);
});
This is how you get the id value on your package.php Page. 这是你在package.php页面上获取id值的方法。
<?php
$_POST['id'];
?>
or you can just store the id in a new variable. 或者你可以将id存储在一个新变量中。
<?php
$id = $_POST['id']
echo($id);
?>
if you arent sure if there are any values being sent by your post you can use this. 如果你不确定你的帖子是否有任何值发送,你可以使用它。
<?php
//This will help you since Post is an array.
print_r($_POST)
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.