Reputation: 53
I need to make modifications to a website that forces me to update data in the page without refreshing its content. The system should change so when a visitor enters a part number, the price for a single unit along with the discount for quantities is displayed. When the visitor chooses a quantity that entitles the visitor for a discount a new price together with corresponding discount band is displayed. The system that we have works now fine but it includes several stages and would not let the user select the quantity at the initial search stage. I need to use jquery to connect to database and fetch the correct price and discount band for the quantity chosen. here is the code that needs changing.
<body >
<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center">
<?php
include ("../includes/java_update.php");
?>
<table width="100%" >
<?php
while ($row = mysql_fetch_array($result))
{
// Increment the total cost of all items
?>
<tr class="inside1">
<td colspan="8"><hr size="1" > </td>
<tr id="inside">
<td><input type="text" name="<?php echo $row["part_number"];?>" value="<?php echo $row["qty"];?>" id="t" onBlur="UpdateQty2(this.name,this.value)" size="3" > </td>
<td><input name="button" type="button"value="Update" class="button"></td>
<td class="disc" width="12%" height="25"><?php echo $row["part_number"]; ?> </td>
<td class="discleft" width="39%" height="25">
<?php
echo $row["disc"]; ?> </td>
<td id="price" width="6%" height="25">£
<?php
for($in =1 ; $in <= 8; $in++)
{
$bb=$row["price_break".($in)];
$halves =explode("-",$bb);
$firstnumber=$halves[0];
$secondnumber=$halves[1];
If ($row["qty"] >= $firstnumber && $row["qty"] <= $secondnumber)
{
echo number_format($row[("price_each".$in)], 2, ".", ",");
tprice ($row["part_number"],$row[("price_each".$in)],$row[("qty")]);
//echo"part_number is ".$row["part_number"];
//echo "<br>";
//echo"price_each is ".$row[("price_each".$in)];
$which=$in;
$totalCost += ($row["qty"] * $row[("price_each".$which)] );
}
}
?> </td>
<td align="center" class="in_stock">
</td>
<td width="9%" height="25" class="pblist" ><select name="pb" >
<?php
$c=$row["price_each1"];// price for single item
for($i = 1; $i <= 8; $i++)
{
$b=$row["price_each".$i];
if ($b !=0.00)
{
$d=(($c-$b)/$c)*100;
$complete=$row[("price_break".$i)]. " ," .round($d)."%";
echo "<option ";
if ($i == $which)
{
echo " SELECTED ";
}
echo ">". $complete ."</option>";
}
}
?>
</select> </td>
<td id="removeit"><a id="removeit" href="cart_wp.php? action=remove_item&id=<?php echo $row["part_number"]; ?>">Remove</a> </td>
</tr>
<script type="text/javascript">
function UpdateQty2(s,m)
{
var part_number=s;
if (isNaN (m)) {
// Not A Number
alert('Please enter a valid no.') ;
} else {
var newQty=m;
document.location.href = 'cart_wp.php?action=update_item&id='+part_number+'&qty='+newQty;
}
}
Upvotes: 0
Views: 468
Reputation: 57105
$.post() documentation
$.ajax({
type: "POST",
url: url,
data: data,
success: success,
dataType: dataType
});
Upvotes: 2