Get div id in php

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>

asked Jul 7, 2016 at 10:12

7

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) { $('#saved-value').html(response); });

answered Jul 7, 2016 at 10:22

awl19awl19

3664 silver badges10 bronze badges

5

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

answered Jul 7, 2016 at 10:51

1

  1. HowTo
  2. PHP Howtos
  3. Store Div Id in a PHP Variable and Pass It to JavaScript

Created: February-23, 2022

  1. What Is the div id in HTML
  2. Store the div id in a PHP Variable
  3. Pass the PHP Variable to a JavaScript Code

This tutorial will cover how to store div id in a PHP variable and pass it to a JavaScript code.

We will answer the following questions.

  1. What is the div id?
  2. How do you store the div id in a PHP variable?
  3. How do you pass the variable to a JavaScript code?

Let’s jump right in.

What Is the div id in HTML

The div id is part of HTML. We use it to identify a unique HTML element and apply CSS or JavaScript to style the element.

Example:

How to store id in variable in PHP?

Yes you can store it in a varibale and reuse it. And you can use the variable $divId anywhere in the page. And if you want to use it in any other pages then you have to put it in any session variable and use that .

What is div id in HTML?

The <div> tag defines a division or a section in an HTML document. The <div> tag is used as a container for HTML elements - which is then styled with CSS or manipulated with JavaScript. The <div> tag is easily styled by using the class or id attribute. Any sort of content can be put inside the <div> tag!

Can I use ID in PHP?

A unique user ID can be created in PHP using the uniqid () function. This function has two parameters you can set.

How can I call HTML ID in PHP?

PHP cannot "call an HTML control". If you want to dynamically modify things in the browser, you'll have to do it client-side using Javascript. It is client-side, so you have to use Javascript, not PHP.

Chủ đề