admin管理员组文章数量:1307635
How can I get this id
into a PHP variable after submit a form? I need to pass the total value to a PHP variable. 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>
How can I get this id
into a PHP variable after submit a form? I need to pass the total value to a PHP variable. 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>
Share
Improve this question
edited Jul 7, 2016 at 10:15
Rory McCrossan
338k41 gold badges320 silver badges351 bronze badges
asked Jul 7, 2016 at 10:12
think_userthink_user
3932 gold badges9 silver badges24 bronze badges
7
- Which PHP variable? Or you want send the value in DIV with the ajax request? – Sougata Bose Commented Jul 7, 2016 at 10:13
-
Your code is already doing what you require. Just use
$_POST['id']
in yourpackage.php
page – Rory McCrossan Commented Jul 7, 2016 at 10:14 - yes i want to send div id value to php variable – think_user Commented Jul 7, 2016 at 10:14
- @RoryMcCrossan i didn't get post value in package.php – think_user Commented Jul 7, 2016 at 10:15
- In that case check the console to see if the request was sent and if there were any errors – Rory McCrossan Commented Jul 7, 2016 at 10:16
2 Answers
Reset to default 5You want the value between the div tags, not the ID, correct?
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 id="saved-value"></div>
Place it anywhere you want on the page.
Then change your jQuery:
}, function(response) {
$('#saved-value').html(response);
});
This is how you get the id value on your package.php Page.
<?php
$_POST['id'];
?>
or you can just store the id in a new variable.
<?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)
?>
本文标签: javascripthow to get div id into php variableStack Overflow
版权声明:本文标题:javascript - how to get div id into php variable? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741847204a2400852.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论