Flavius Pintican Flavius Pintican - 8 months ago 25
jQuery Question

jquery how can I get data from html table row

I have the following table:

<table cellspacing="0" cellpadding="0" id="product">
<th colspan="2">Nr products</th>
<?php foreach ($productsInStock as $product) : ?>
<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();?>">
<?php endforeach; ?>

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


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>