2014-01-09 24 views
0

我有购物车页面中的文本框是为了更新数量存在,我正在使用jquery来收听点击事件&获取productid &的值的文本框。 Productid我越来越好,但文本框的值始终是第一个文本框中的值。更新从第一个文本框中获取值的文本框的值只有

这里是车文件的代码

echo "<tr>"; 
      echo "<th><img src=".$row["image_location"]."></th>"; 
      echo "<th>".$row["product_name"]."</th>"; 
      echo "<th><input type='text' id='quantity' name='quantity' required='required' autocomplete='off' value=".$row["quantity"].">"; 
      echo "&nbsp"; 
      echo $row["type"]."</th>"; 
      echo "<th>".$row["price"]."</th>"; 
      echo "<th>"."&#8377;&nbsp;".$subtotal."</th>"; 
      echo "<th><div class='buttoncircle' id='".$row["productid"]."'>Update</div></th>"; 
      echo "<th><a href='removefromcart.php?productid={$row["productid"]}' class='buttoncircle' style='margin-left:-65px'>Remove</a></th>"; 
     echo "</tr>"; 

这里是Javascript代码。

<script> 
$('.buttoncircle').live('click',function() { 
    var productid = $(this).attr('id'); 
    var quantity = $('#quantity').val(); 
    window.open('db_changequantity.php?quantity='+quantity+'&productid='+productid,'_self'); 
}); 

谁能帮助从只有第一个调用特定的文本框&没有价值?

回答

1

为数量字段添加动态标识 - id='quantity_".$row["productid"]."',并将其映射到javascript var quantity = $('#quantity_'+productid).val();中。

在PHP

echo "<tr>"; 
    echo "<th><img src=".$row["image_location"]."></th>"; 
    echo "<th>".$row["product_name"]."</th>"; 
    echo "<th><input type='text' id='quantity_".$row["productid"]."' name='quantity' required='required' autocomplete='off' value=".$row["quantity"].">"; 
    echo "&nbsp"; 
    echo $row["type"]."</th>"; 
    echo "<th>".$row["price"]."</th>"; 
    echo "<th>"."&#8377;&nbsp;".$subtotal."</th>"; 
    echo "<th><div class='buttoncircle' id='".$row["productid"]."'>Update</div></th>"; 
    echo "<th><a href='removefromcart.php?productid={$row["productid"]}' class='buttoncircle' style='margin-left:-65px'>Remove</a></th>"; 
    echo "</tr>"; 

使用Javascript:

$('.buttoncircle').live('click',function() { 
    var productid = $(this).attr('id'); 
    var quantity = $('#quantity_'+productid).val(); 
    window.open('db_changequantity.php?quantity='+quantity+'&productid='+productid,'_self'); 
}); 
+0

这是URL:db_changequantity.php量=未定义&的productid = 32? 查看未精订的数量?? –

+0

你的mozila浏览器中有firebig吗?请检查'id ='quantity _“。$ row [”productid“]。”''它在源码 –

+0

'id = quantity _“中正确显示为红色。$ row [”productid“]'你可以在qty字段中替换这个吗? –