I have a PHP shopping cart that is echoing out price and quantity into a table. The ids of each Td are being named p1,p2,p3..etc. and q1,q2,q3..etc. so that I can target them to be used to show total cart cost with javascript. When I try to get the id's value and put it in an alert I get "undefined". I can see that the value is in fact a number so why am I getting undefined? Is there a way to access the value of a Td by its id so that it is not undefined? I would appreciate your help. Will post more code if needed. 

```
    var p1= document.getElementById("p1").value;
    var q1= document.getElementById("q1").value;
    var total= parseFloat(p1) * parseFloat(q1);  
    window.alert(p1); 

```

Here is the code for this page:

```
<div id="shopping-cart">
    <div class="txt-heading">
        <div class="label">Shopping Cart</div> 
        <a id="btnEmpty"><img src="empty-cart.png" id= "emptycart" 
alt="empty-cart" title="Empty Cart"  /></a>
    </div>

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "secure_login";
$member_id = $_SESSION['login_user'];

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 
?>

 <?php 
 $query = "select * from tbl_cart WHERE member_id= '$member_id'";
 $result = mysqli_query($conn,$query);
 if (!$result) {
 printf("Error: %s\n", mysqli_error($conn));
 exit();
}

echo "<table id='anyclass'>";
echo "<tr>
         <th id='product1'>Product</th>
         <th id='price1'>Price</th>
         <th id='quantity1'>Quantity</th>
         <th id='remove1'>Remove</th>

    </tr>";

$i=1;
while($row = $result->fetch_assoc()) {  

echo "<tr class= 'trhide'>";

echo          "<td id='product'>".$row['product_id']."</td>";

echo          "<td id= 'p$i' >".$row['price']."</td>"; 
echo          "<td id= 'q$i' >". "<input style='border:none' type = 'text' 
class= 'change' id= $row[id] value= $row[quantity] name= $row[id] data-id= 
$row[id] >" . "</td>";

echo          "<td id= 'delete'><span class='delete' data-id= $row[id] ><img 
src=delete.svg></span></td>   
  </tr>";

  $i++;
}

echo  "<tr>
          <td>Total:</td>
          <td id= 'total'></td>
          <td></td>
          <td></td> 

  </tr>";
echo "</table>";

?>

```