creative creative - 1 year ago 134
jQuery Question

how to get div id into php variable?

How can I get this

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">
<th>Total Price</th>
<input class="form-control1" type='text' id='txt_totalprice' name='txt_totalprice[]'/>

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) {

Answer Source

You 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) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download