Jump to content

Javascript to sum total 2 drop down options...


joshluv33

Recommended Posts

I am working with existing php code for my photography site which generates two drop down lists.  The code retrieves Mysql info for both the size of print the client wants and separately for the color choice of the photo.  Each table in Mysql has a price associated with the product.  I would like the client to choose both options and have the sum totaled before it is sent to the cart.  Let me show you where I am at now with the code.  I appreciate any help...

I've attached the code.  Again I appreciate any help with this.

[code]
function addprice(str)
{
var itemLoc,itemLocLink;
itemLoc=document.getElementById('add2cart');
itemLoc.href=itemLoc.href + str.value;

itemLocLink=document.getElementById('add2cartlink');
itemLocLink.href=itemLocLink.href + str.value;

}
</script>

  <?
echo "<tr><td class=\"photo_details\" bgcolor=\"#000000\" style=\"border: 1px solid #eeeeee; padding: 5px;\">";
echo "<div align=\"center\" style=\"background-color: #000000; margin-bottom: 10px; padding: 3px;\"><b>Order Prints</b></div>";
$x = 1;
$print_result = mysql_query("SELECT * FROM prints where quan_avail > 0 order by 'porder'", $db);
$print_rows = mysql_num_rows($print_result);
echo "<select name='prints' onChange='addprice(this);'>";
echo "<option>Select Prints</option>";
while($print=mysql_fetch_assoc($print_result)){
$name = $print['name'];
$price = $print['price'];
$id = $print['id'];
echo "<option value='$id'>$name--->$$price</option>\n";
}
echo "</select>";
if($print->quan_avail != "999"){
echo "<br />" . $print->quan_avail;
}
echo "</font><br>";
?>

<?

$x = 1;
$color_result = mysql_query("SELECT * FROM color", $db);
$color_rows = mysql_num_rows($color_result);
echo "<select name='color' onChange='addprice(this);'>";
echo "<option>Select Color</option>";
while($color=mysql_fetch_assoc($color_result)){
  $name = $color['name'];
  $price = $color['price'];
echo "<option value='$price'>$name--->$$price</option>\n"
}
echo "</select>";
if($print->quan_avail != "999"){
echo "<br />" . $print->quan_avail;
}echo "</font><br>";
?>
<span style="float: center"><a id="add2cart" href="public_actions.php?pmode=add_cart&amp;ptype=p&amp;gid=<?=$_GET['gid'];?>&amp;sgid=<?=$_GET['sgid'];?>&amp;pid=<?=$_GET['pid'];?>&amp;prid=<?=$print->id;?>" class="photo_links"><img src="images/cart.gif" valign="middle" border="0" /></a> <a id="add2cartlink" href="public_actions.php?pmode=add_cart&amp;ptype=p&amp;gid=<?=$_GET['gid'];?>&amp;sgid=<?=$_GET['sgid'];?>&amp;pid=<?=$_GET['pid'];?>&amp;prid=" class="photo_links">Add To Cart</a></span>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.