php - Hundreds of buttons in one page with same name and same ids, how to differentiate? -


i have problem here, have page hundreds of products, each have "add cart" button. problem buttons have same id , same name. doing here when want click button, product name goes the cart. don't think work ids , names same. can tell me how solve this?

example of code:

    <li class="ms-tt grid_3" data-id="id-1" data-type="digital">                         <div class="m-thumb entry-image hover-content">                             <a href="#"><img src="images/jewellery-tools/casting-soldering1/14.jpg" alt='flasks stainless steel perforated c-16'></a>                             <div class="image-overlay">                                 <div class="buttons-tt clearfix">                                     <a class="permalink" href="#"><i class="icon-link"></i></a>                                     <a class="zoom" href="images/jewellery-tools/casting-soldering1/14.jpg" data-gal="photo[portfolio]" title='flasks stainless steel perforated c-16'><i class="icon-resize-full"></i></a>                                 </div>                             </div>                         </div>                         <p class="post-meta-ab"><span><a href="#">flasks stainless steel perforated c-16</a></span><br />                         <span>details: flasks stainless steel perforated casting 3" dia x 5",6" & 7"</span><br />                         <span><i class="icon-circle"></i>shipping weight: 750gms</span><br /><span><i class="icon-circle"></i>price: &#8364; 17.00</span><br />                         <span><i class="icon-circle"></i>quantity: <input type="text" style="width:20px" maxlength="100" name="a1" id="a1" />                         <input type="submit" value="add" style="margin-top:-8px" class="btn btn-danger" name="asubmit" id="a1sub" /></span></p>                     </li> 

please tell me how solve problem?

p.s there possible way find button clicked? can't use $(this).clicked

guerro's technique did trick me. please see answer below. thanks

you can braziliam way, call "gambiarra"

$('input [type=submit]').click(function(){    var productname = $(this).parent().find('.post-meta-ab a').html(); }); 

ps. if cant set unique id dom elements, don't use @ all.

basically each product on list have structure:

<li class="ms-tt grid_3" data-id="id-1" data-type="digital">                         <div class="m-thumb entry-image hover-content">                             <a href="#"><img src="images/jewellery-tools/casting-soldering1/14.jpg" alt='flasks stainless steel perforated c-16'></a>                             <div class="image-overlay">                                 <div class="buttons-tt clearfix">                                     <a class="permalink" href="#"><i class="icon-link"></i></a>                                     <a class="zoom" href="images/jewellery-tools/casting-soldering1/14.jpg" data-gal="photo[portfolio]" title='flasks stainless steel perforated c-16'><i class="icon-resize-full"></i></a>                                 </div>                             </div>                         </div>                         <p class="post-meta-ab"><span><a href="#">flasks stainless steel perforated c-16</a></span><br />                         <span>details: flasks stainless steel perforated casting 3" dia x 5",6" & 7"</span><br />                         <span><i class="icon-circle"></i>shipping weight: 750gms</span><br /><span><i class="icon-circle"></i>price: &#8364; 17.00</span><br />                         <span><i class="icon-circle"></i>quantity: <input type="text" style="width:20px" maxlength="100" name="a1" id="a1" />                         <input type="submit" value="add" style="margin-top:-8px" class="btn btn-danger" name="asubmit" id="a1sub" /></span></p>                     </li> 

inside <li> element have button , have <p> product title, , <p> have "post-meta-ab" class. when say:

$('input [type=submit]').click(function(){ //here you'r saying, "when input submit clicked execute code above"    var productname = $(this).parent().find('.post-meta-ab a').html(); // here saying, $(this) means input submit clicked, , parent() means <li>, , tell element post-meta-ab class , inside it. }); 

understand now?


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -