Flavius Pintican Flavius Pintican - 5 months ago 16
jQuery Question

jquery how can I get data from html table row

I have the following table:

<table cellspacing="0" cellpadding="0" id="product">
<tr>
<th>Name</th>
<th>Category</th>
<th>Price</th>
<th colspan="2">Nr products</th>
</tr>
<?php foreach ($productsInStock as $product) : ?>
<tr>
<td><?php echo $product->getName(); ?></td>
<td><?php echo $product->getCategory(); ?></td>
<td><?php echo $product->getPrice().ProductController::coin; ?></td>
<td><?php echo $product->getNrProducts(); ?></td>
<td><button type="submit" value="Delete" class="upload" onclick="deleteDataTable();">Delete</button></td>
<input type="hidden" name="hiddenfieldname" class="hidden" value="<?php echo $product->getId();?>">
</tr>
<?php endforeach; ?>
</table>


I need the value for every hidden field but I only get the first :

x = ('.hidden').val() // gives the first value


How can I get the different values after every click on delete button

Answer

Simplest solution is pass the ID as parameter to deleteDataTable() function.

<td><button type="submit" value="Delete" class="upload" onclick="deleteDataTable(<?php echo $product->getId();?>);">Delete</button></td>