javascript code for price

General ShopSite user discussion

javascript code for price

Postby gene » Sun Nov 08, 2009 7:38 pm

I am creating a javascript code where a page will show the amount of "savings in $" and the "% savings". I used var [-- PRODUCT.Price --] and var [-- PRODUCT.SaleAmount --]. However, when the script execute it will get the amount in the database with a dollar sign? How do I get rid of this dollar sign in the code? Or do I miss something? Need your help. Thanks.
gene
 
Posts: 122
Joined: Mon Feb 09, 2009 10:54 pm
Location: Philippines

Postby Jim » Sun Nov 08, 2009 8:05 pm

Prices are always displayed with the currency symbol. You will probably need to do something in your code to strip it off if you need to use it for calculations.
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah

Postby gene » Sun Nov 08, 2009 8:14 pm

Anyone here who could me out or give suggestions?
gene
 
Posts: 122
Joined: Mon Feb 09, 2009 10:54 pm
Location: Philippines

Removes Dollar Sign, and Comma, calculates discount

Postby mjbrunelle » Thu Nov 12, 2009 7:42 pm

I pull the discount for pricing from the Coupon name that ShopSite stores in the customer cookie. Then calculate the discounted price for display.
ie: "|DIS30Toyota Corporation"

function disPrice(listPrice)
{
var cookie = document.cookie;
var discount = cookie.indexOf("|DIS");
var signedIn = cookie.indexOf("|yes");
var Price = listPrice;
if ((discount != 0) && (signedIn != -1))
{
var disPercentage = cookie.substring(discount + 4,discount + 6);
var workPrice = listPrice.substring( 1, listPrice.length);
var locComa = workPrice.indexOf(",",0);
if (locComa)
{
workPrice = workPrice.substring(0,locComa) + workPrice.substring(locComa+1,workPrice.length);
}
var Price = (workPrice * ((100 - disPercentage)/100)).toFixed(2);
if (Price.length>6)
{
Price = Price.substring(0,1) + "," + Price.substring(1,Price.length);
}
Price = "$" + Price;
}
document.write(Price);
}
mjbrunelle
 
Posts: 147
Joined: Sun Jun 21, 2009 5:09 am

forgot code from Product Template to pass price

Postby mjbrunelle » Thu Nov 12, 2009 7:44 pm

<div class="recDPRICE"><script language="javascript">disPrice('[-- PRODUCT.Price --]');</script></div>
mjbrunelle
 
Posts: 147
Joined: Sun Jun 21, 2009 5:09 am


Return to User Forum

Who is online

Users browsing this forum: Bing [Bot] and 100 guests