Ich benutze Sitzungsvariable, um die Elemente im Warenkorb zu verfolgen. Ich erzeuge eine Tabelle mit einer Schleife, um den Inhalt des Warenkorbes anzuzeigen. Der Code für die Tabelle ist wie folgt:Setzen Wert von HTML-Element von Javascript
<?php
$count=0;
$grandTotal=0;
foreach($_SESSION['cart'] AS $product) {
$table=$product['table'];
$id=$product['id'];
$Name=$product['name'];
$qty=$product['quantity'];
$price=$product['price'];
$total=$qty*$price;
$grandTotal +=$total;
?>
<tr>
<td class="cart_product">
<img src=<?php $i=2; echo "images/".$table."/".$id.".jpg"?> height="150" width="150">
</td>
<td class="cart_description">
<h4><a href=""><?php echo $Name?></a></h4>
<p><?php echo "Web ID: ".$id?></p>
</td>
<td class="cart_price">
<p><?php echo $price?></p>
</td>
<td class="cart_quantity">
<div class="cart_quantity_button">
<a class="cart_quantity_up" href="addToCart.php?table=<?php echo $table ?>&action=inc&id=<?php echo $id ?>" id="increment"> + </a>
<input class="cart_quantity_input" type="text" name="quantity" id="qty" value="<?php echo $qty?>" autocomplete="off" size="2">
<!-- <p class="cart_quantity_input" name="qunatity" id="qty"><?php echo $qty?></p>-->
<a class="cart_quantity_down" href="addToCart.php?table=men&action=dec&id=<?php echo $id ?>" name="decreament" > - </a>
</div>
</td>
<td class="cart_total">
<p class="cart_total_price"><?php echo $total ?></p>
</td>
<td class="cart_delete">
<a class="cart_quantity_delete" href="addToCart.php?table=men&action=del&id=<?php echo $id ?>"><i class="fa fa-times"></i></a>
</td>
</tr>
<?php
}
$tax=0.15*$grandTotal;
?>
I Problem innerhalb a
Tags mit +
und -
Tasten habe. Ich möchte den Wert im Eingabefeld quantity
erhöhen oder verringern. Aber da ich eine Tabelle in einer Schleife erzeuge, kenne ich die ID von jedem Feld nicht. Ich möchte so etwas tun:
<script>
$(document).ready(function() {
$("#increment").click(function() {
var oldval=document.getElementById("qty").value;
var newval=parseInt(oldval);
document.getElementById("qty").value=newval++;
});
});
</script>
Aber diese Methode inkrementiert immer erste Menge Feld in der Tabelle. Wie bekomme ich IDs von anderen Mengenfeldern in der Tabelle?
zeigen Sie die code.adda Geige oder so etwas – XYZ