2010-02-05 3 views
4

Je suis en train de convertir ces formulaires ajax (un exemple)jQuery sélectionner l'entrée [type = image] frères et sœurs

<table> 
<tr> 
      <td>Prov</td><td>Cod</td><td>Nombre</td><td>Precio</td><td>Stock1</td><td></td><td></td> 
     </tr> 

       <tr class="o d"> 
        <td class="provName">Karabitian</td> 

        <td class="cod d">494011135</td> 
        <td class="name" id="artID13899">Eje del. m505 y4ch98040 comp. s/cierre Shimano</td> 
        <td class="alignright">$&nbsp;69.00</td> 
        <td class="center">-</td> 
        <td class="add"> 
       <nobr> 

        <form name="formularioAgregaItem" action="script.php" method="POST" autocomplete="off" class="add"> 
         <fieldset> 
          <input name="function" value="cartAddByBarcode" type="hidden"> 
          <input name="barcode" value="KAR005834" type="hidden"> 
          <input name="orderID" value="23333" type="hidden"> 
          <input name="qty" id="qty13899" size="2" maxlength="3" class="i" value="15" type="text"> 
          <input src="add_16x16.gif" alt="agregar a la orden" type="image"> 
         </fieldset> 
        </form> 

       </nobr> 
       </td> 
       </tr> 

       <tr class="o d"> 
        <td class="provName">Karabitian</td> 

        <td class="cod d">494011137</td> 
        <td class="name" id="artID13900">Eje del. m565 y4c698010 comp. s/cierre Shimano</td> 
        <td class="alignright">$&nbsp;260.00</td> 
        <td class="center">-</td> 
        <td class="add"> 
       <nobr> 

        <form name="formularioAgregaItem" action="script.php" method="POST" autocomplete="off" class="add"> 
         <fieldset> 
          <input name="function" value="cartAddByBarcode" type="hidden"> 
          <input name="barcode" value="KAR005835" type="hidden"> 
          <input name="orderID" value="23333" type="hidden"> 
          <input name="qty" id="qty13900" size="2" maxlength="3" class="i" value="15" type="text"> 
          <input src="add_16x16.gif" alt="agregar a la orden" type="image"> 
         </fieldset> 
        </form> 

       </nobr> 
       </td> 
       </tr> 

       <tr class="o d"> 
        <td class="provName">Karabitian</td> 

        <td class="cod d">494011143</td> 
        <td class="name" id="artID13905">Eje del. m775 y26k98030 comp. s/cierre Shimano</td> 
        <td class="alignright">$&nbsp;290.00</td> 
        <td class="center">-</td> 
        <td class="add"> 
       <nobr> 

        <form name="formularioAgregaItem" action="script.php" method="POST" autocomplete="off" class="add"> 
         <fieldset> 
          <input name="function" value="cartAddByBarcode" type="hidden"> 
          <input name="barcode" value="KAR005837" type="hidden"> 
          <input name="orderID" value="23333" type="hidden"> 
          <input name="qty" id="qty13905" size="2" maxlength="3" class="i" value="15" type="text"> 
          <input src="add_16x16.gif" alt="agregar a la orden" type="image"> 
         </fieldset> 
        </form> 

       </nobr> 
       </td> 
       </tr> 

       <tr class="o d"> 
        <td class="provName">Karabitian</td> 

        <td class="cod d">494011153</td> 
        <td class="name" id="artID13910">Eje del. r500 y4bg98030 comp. s/cierre Shimano</td> 
        <td class="alignright">$&nbsp;73.00</td> 
        <td class="center">-</td> 
        <td class="add"> 
       <nobr> 

        <form name="formularioAgregaItem" action="script.php" method="POST" autocomplete="off" class="add"> 
         <fieldset> 
          <input name="function" value="cartAddByBarcode" type="hidden"> 
          <input name="barcode" value="KAR005841" type="hidden"> 
          <input name="orderID" value="23333" type="hidden"> 
          <input name="qty" id="qty13910" size="2" maxlength="3" class="i" value="15" type="text"> 
          <input src="add_16x16.gif" alt="agregar a la orden" type="image"> 
         </fieldset> 
        </form> 

       </nobr> 
       </td> 
       </tr> 

       <tr class="o d"> 
        <td class="provName">Karabitian</td> 

        <td class="cod d">494011157</td> 
        <td class="name" id="artID13914">Eje del. r560 y4c498010 comp. s/cierre Shimano</td> 
        <td class="alignright">$&nbsp;137.00</td> 
        <td class="center">-</td> 
        <td class="add"> 
       <nobr> 

        <form name="formularioAgregaItem" action="script.php" method="POST" autocomplete="off" class="add"> 
         <fieldset> 
          <input name="function" value="cartAddByBarcode" type="hidden"> 
          <input name="barcode" value="KAR005845" type="hidden"> 
          <input name="orderID" value="23333" type="hidden"> 
          <input name="qty" id="qty13914" size="2" maxlength="3" class="i" value="15" type="text"> 
          <input src="add_16x16.gif" alt="agregar a la orden" type="image"> 
         </fieldset> 
        </form> 

       </nobr> 
       </td> 
       </tr> 
</table> 

Mais je ne peux pas comprendre comment obtenir les entrées de la même ligne i cliqué

$('input[type=image]').click(function(){ 
    // insert voodoo go get inputs here 
    // ajax call 
    return false; 
}); 

Je ne peux pas faire quelque chose comme $ (entrée [name = "code-barres"]) Toutes les idées?

Répondre

12

vous devez faire qqch comme:

$('input[type=image]').click(function(){ 
    var image = $(this); 
    var parent = image.parent(); // this will be the fieldset, could also do .closest('fieldset)', if the fieldset is not the immediate parent 
    var neededInput = $('input[name=barcode]', parent); 
    // do something with it 
    return false; 
}); 

ou en utilisant la siblings() -method

$('input[type=image]').click(function (event){ 
    event.preventDefault(); 
    var $image = $(this); 
    var $neededInput = $image.siblings('input[name=barcode]'); 
    // do something with it 
}); 
+0

travaillé comme un charme, merci! –

+0

vous êtes les bienvenus! –

1

dans votre fonction de clic, this sera une référence à l'image que vous avez cliqué. Ainsi, vous pouvez faire

$(this).siblings() 

ou

$(this).closest('fieldset').find(...); 
+0

probablement je vous ai mal compris, mais avec cela je n'ai eu que les autres entrées de type image ... –