Note that there are some explanatory texts on larger screens.

plurals
  1. POassign unique id to <input> button and read it using jquery
    text
    copied!<p>I have a minor problem, basically I have a hidden input button which is loaded with a unique value from a database table: <code>&lt;input type="hidden" name="ProductId" class="ProductId" value='.$row["ProductId"].' /&gt;</code> This button gets repeated according to how many rows are returned through this method:</p> <pre><code>while ($row = $result-&gt;fetch()) { echo '&lt;table class="cart-row" cellspacing="0" cellpadding="0" width="100%"&gt;'; echo '&lt;tbody&gt;'; echo '&lt;tr&gt;'; echo '&lt;td width="75"&gt;&lt;img border="0" width="59px" height="78px" title="" alt="" src=' . $row["ImagePath"] .'&gt;&lt;/td&gt;'; echo '&lt;td width="203"&gt;&lt;span class="itemElements itemName"&gt;'. $row["Name"] .'&lt;/span&gt;&lt;/td&gt;'; echo '&lt;td width="203"&gt;&lt;input type="submit" class="btnMinus linkbtnType2" value="-"&gt;&lt;input type="submit" class="btnPlus linkbtnType2" value="+"&gt;&lt;/td&gt;'; echo '&lt;td width="135"&gt;&lt;span class="qtyNum"&gt;('. $row["Qty"] .')&lt;/span&gt; &lt;br /&gt;'; echo '&lt;input type="hidden" name="ProductId" class="ProductId" value='.$row["ProductId"].' /&gt;'; echo '&lt;span class="qtyRemoveLink"&gt;&lt;input type="submit" class="btnRemove linkbtn" value="Remove"&gt;&lt;/td&gt;'; echo '&lt;td width="180"&gt;&lt;span class="itemElements orderStatus"&gt;In Stock Usually dispatched within 24 hours&lt;/span&gt;&lt;/td&gt;'; echo '&lt;td width="175" class="itemPriceRow"&gt;&lt;span id="itemPrice"&gt;€ '. $row["Price"] .'&lt;/span&gt;&lt;/td&gt;'; echo '&lt;/tr&gt;'; echo '&lt;/tbody&gt;'; echo '&lt;/table&gt;'; echo '&lt;br&gt;'; } </code></pre> <p>Im using a jQuery method to use read this value from the hidden button however it is only reading the value from the first input button generated. I tried changing the the button from an ID to a class but with no luck.</p> <p>This is the jQuery method:</p> <pre><code>$('.btnRemove').click(function() { var productId = $(".ProductId").val(); $.ajax({ type: "POST", url: "functions/deleteCartItem.php", data: "productId="+productId+ "", success: function(msg){ alert(msg); } }) }) </code></pre> <p>A possible solution I can think of is to add a unique <code>id</code> to each button so they can be identified not only by name but also by <code>id</code>. However this poses a problem in reading it from the jQuery method.</p> <p>Any ideas? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload