2014-05-03 49 views
0

我想獲取其質量已更改的元素的當前價格。 我只是能夠改變第一個元素的價格,但不是其他 請幫助我從數量的下拉菜單中獲取所選元素的數量。從for循環生成的td標記中獲取輸入標記的值

<script type="text/javascript"> //quantity retrival 
    $(document).ready(function() { 

    $('.quantityx').change(function(){ 
     alert("message"); 

     var tot =$('#pricexx').val()* this.value; 
     alert(this.parent.find('input[name=pricexx]').val()); 

     }); 

    }); 
    </script> 

    <table id="mytable"> 

        <% 
         int i = 0; 
         while (it.hasNext()) { 
          i++; 
          Product_List PL = (Product_List) it.next(); 

          list.add("" + PL.getProduct_id()); 
          String order = list.toString(); 
          session.setAttribute("orders", order); 
        %><tr class="row"> 



         <td class="delete"> 
          <div class="centererer"> 
           <form action="PDelete" method="get"> 
            <input type="hidden" name="p_id" value="<%=PL.getProduct_id()%>" 
             id="Product_id" /> <input type="submit" class="close"> 
           </form> 
          </div> 
         </td> 
         <td class="image"><img src="<%=PL.getImage()%>" width="86" 
          height="86" /></td> 
         <td class="name"><%=PL.getBrand()%> <%=PL.getDetail()%></td> 
         <td class="size"><%=PL.getCloth_size()%></td> 

         <td class="price">&#8377;<input name="pricexx" type="text" disabled="disabled" value="<%=PL.getPrice()%>"></td> 
         <td class="quauntity"> 
         <select class="quantityx"> 
       <option value="1" selected="selected">1</option> 
       <option value="2">2</option> 
       <option value="3">3</option> 
       <option value="4">4</option> 
       <option value="5">5</option> 
      </select> 


          </td> 
         <%!int totalprice, netprice = 0,quant=1;%> 
         <% 
          totalprice = quant * PL.getPrice(); 
         %> 
         <% 
          netprice = totalprice + netprice; 
         %> 

         <td class="price">&#8377;<input id="tp" type="text" disabled="disabled" value="<%=totalprice%>"></td> 

        </tr> 
        <% 
         } 
        %> 
       </table> 
       <!--   --> 
       <input type="hidden" value="<%=list.toString()%>" name="array" /> <br /> 
       <br /> 
       <br /> 
       <br /> 
       <table> 
        <tr> 
         <!-- <td class="size"></td> --> 
         <td class="total">TOTAL <span class="pricex">&#8377;<%=netprice%></span></td> 


        </tr> 
       </table> 

回答

0

您的選擇器對於獲取當前input[name=pricexx]是不正確的。你應該這樣做

var input = $(this).parent().parent().find('input[name=pricexx]'); 
var tot = input.val() * this.value; 
+0

謝謝..它的工作! – vaibhav