Where do I begin? Been working to build some similar functionality to the below code using php. To do like they are doing on this site flooring site by converting quantities.
http://www.hardwooddirect.com/displayseries.asp?mID=1&sID=8
Pulled out this code out of the document to look at it a little closer. Pretty much want to create some of this usability standard in the business with php. Seems like most of the sites with similar capability are also .asp driven. Now php is awesome at doing behind the scenes conversions, but this one is a challenge.
<script language="javascript">
<!--
//----- Validate for Empty QTY and Calculate SQ Ft Conversion ------
function ValidateConvertQty(theForm)
{
if (theForm.quantity.value == "")
{
alert("Please enter a value for the Quantity field.");
theForm.quantity.focus();
return (false);
}
if (theForm.sellunit.value == "sf")
{ intFactor=1000
// Check if packunit = 0 then call for price
if (Math.round(theForm.packunit.value*intFactor) == 0)
{ alert ("Please call 877-4AFLOOR to order this product.")
return (false);
}
//check to see if quantity value can evenly be divided by packunit value example quantity=35;packunit=25 35%25 !=0
if ((Math.round(theForm.quantity.value*intFactor) % Math.round(theForm.packunit.value*intFactor)) == 0)
{
//-- Only sf now -- newQty=theForm.quantity.value/theForm.packunit.value
//-- alert("We sell this item by the carton. It will go into the shopping cart as "+newQty +" cartons.");
//-- Only sf now -- theForm.quantity.value = newQty
//-- Only sf now -- theForm.sellunit.value = "ctn"
// Added this to allow no less than 3 cartons on a product.
if (Math.ceil(theForm.quantity.value/theForm.packunit.value) < 3)
{
alert("The order minimum is 3 cartons or bundles. To satisfy your request, please change quantity to "+Math.round(3 * theForm.packunit.value * intFactor)/intFactor+".");
theForm.quantity.value = Math.round(3 * theForm.packunit.value * intFactor)/intFactor
return (false);
} else {
return (true);
}
}
else
{
newQty=Math.ceil(theForm.quantity.value/theForm.packunit.value)
// alert(newQty);
newSFQty=Math.round(newQty * theForm.packunit.value * intFactor)/intFactor
//alert (newQty+"*"+theForm.packunit.value+"="+newSFQty);
//alert("We sell this item by the carton. For "+ theForm.quantity.value +" Sq.Ft. you need "+newQty+" cartons. You may change quantity by viewing the shopping cart.");
//-----------
// Added this to allow no less than 3 cartons on a product.
if (newQty < 3)
{
alert("The order minimum is 3 cartons or bundles. To satisfy your request, please change quantity to "+Math.round(3 * theForm.packunit.value * intFactor)/intFactor+".");
theForm.quantity.value = Math.round(3 * theForm.packunit.value * intFactor)/intFactor
} else {
alert("This item ships by the carton or bundle. To satisfy your request for "+theForm.quantity.value +" SF, please change quantity to "+newSFQty+".");
theForm.quantity.value = newSFQty; //Math.round(newSFQty * intFactor)/intFactor
}
//-----------
//theForm.sellunit.value = "ctn"
return (false);
}
theForm.quantity.focus();
return (false);
}
}
function ValidateQty(theForm)
{
if (theForm.quantity.value == "")
{
alert("Please enter a value for the Quantity field.");
theForm.quantity.focus();
return (false);
}
}
-->
</script>