В настоящее время я строю интернет-магазин и в настоящее время занимаюсь интеграцией затрат на доставку на страницу оформления заказа, чтобы при выборе пользователем одной из двух переключателей ОБЩАЯ ЦЕНА обновлялась в соответствии с выбором стоимости доставки.
HTML код:
<h1 id='h1_centre'> Your Cart </h1>
<div id="shopping-cart">
<table>
<tbody>
<tr>
<th style='text-align:left; font-size: 1.5em;'><strong>Product</strong></th>
<th style='text-align:left; font-size: 1.5em;'><strong></strong></th>
<th style='text-align:left; font-size: 1.5em;'> <strong>Description</strong></th>
<th style='text-align:left; font-size: 1.5em;'><strong>Quantity</strong></th>
<th style='text-align:left; font-size: 1.5em;'><strong>Price</strong></th>
<th style='text-align:left; font-size: 1.5em;'><strong>VAT</strong></th>
<th style='text-align:right; font-size: 1.5em;'><strong>Total</strong></th>
<th style='text-align:right; font-size: 1.5em;'></th>
</tr>
<tr>
<td>
<div id="product_image_checkout_large">
<img src="../images/pillows.png"
</div>
</td>
<td>Pillows</td><td>Enter Text Here - Extra Information</td><td>1</td>
<td>£20.00</td><td>£4.00</td><td style='text-align: right;'>£24.00</td>
<td style='text-align:right;'>
<form action='remove_cart_item.php' method='post'>
<input type='text' name='cart_item' value='10' style='display: none;'>
<button type='submit' value='Remove' style='background: none; border: none;'>
<img src='../images/removal_cross.png' style='width: 25px; height: 25px'>
</button>
</form>
</td>
</tr>
<tr>
<td colspan='8' align=right style='font-size: 1.2em;'> Total: £24.00
</td>
</tr>
<tr>
<td colspan='7' align=right style='font-size: 1em;'>
<input type='radio' name='delivery' value='9.99' checked>1st Class - £9.99
</td>
<td colspan='7' align=right style='font-size: 1em;'>
<input type='radio' name='delivery' value='2.99' checked>2nd Class - £2.99
</td>
</tr>
<tr>
<td colspan="8" align=right style="font-size: 1.5em;" >
£26.99
</td>
</tr>
<tr>
<td colspan="8" align=left >
<!-- Button -->
</td>
</tr>
</tbody>
</table>
</div>
PHP-код, который генерирует общую стоимость на основе данных записей корзины покупок из SQL:
$sql3="SELECT SUM(total_with_vat) FROM shopping_cart WHERE username='$myusername'";
// Posting Result
$result3 = mysqli_query($connection, $sql3);
// Counting Results
$count=mysqli_num_rows($result3);
if($count==0) {
} else {
if ($result3 = mysqli_query($connection, $sql3)){
while($row = $result3->fetch_array()) {
$total_new_vat = $row['0'];
echo "<tr ><td colspan='8' align=right style='font-size: 1.2em;'> Total: "."£".$total_new_vat."</td></tr>";
}
}
PHP-код для генерациирадиокнопки для 2 почтовых опций :
$root = $_SERVER['DOCUMENT_ROOT'];
include "$root/ecommerce/connection.php";
echo "<tr >";
$sql4="SELECT * FROM delivery_charges where active= 'yes'";
// Posting Result
$result4 = mysqli_query($connection, $sql4);
// Counting Results
$count=mysqli_num_rows($result4);
if($count==0) {
} else {
if ($result4 = mysqli_query($connection, $sql4)){
while($row = $result4->fetch_array()) {
$class = $row['type'];
$delivery_amount = $row['amount'];
echo "<td colspan='7' align=right style='font-size: 1em;'><input type='radio' name='delivery' value='$delivery_amount' checked>$class - "."£".$delivery_amount."</td>";
}
}
Когда пользователь выбирает радиокнопку, я хочу, чтобы ОБЩАЯ ЦЕНА была обновлена, чтобы включить это, без перезагрузки страницы.
Я понимаю, что мне нужен JS-код для манипулирования кодом на странице, но id любит некоторую помощь, как это сделать.
Спасибо. Стэн.