开发者

JavaScript Calculate Pricing form not working on PC. Works on Mac. Can someone find the error(s)?

开发者 https://www.devze.com 2022-12-21 17:18 出处:网络
Can anyone help me spot the problem on this PLEASE? I\'m eternally grateful for the help this site has been already and appreciate any advice or thoughts. Thank you.

Can anyone help me spot the problem on this PLEASE? I'm eternally grateful for the help this site has been already and appreciate any advice or thoughts. Thank you.

The actual page can be seen here: http://www.procollage.com/pricing/photo-collage-pricing.html

 <script LANGUAGE="JavaScript">
function calculate(PricingForm) {
    height = PricingForm.height.value;
    width = PricingForm.width.value;
    photos = PricingForm.photos.value;
    lgtext = PricingForm.lgtext.value;
    mountlam = PricingForm.mount.value;
    mountlam = PricingForm.lam.value;

    price = GetPrice(PricingForm, height, width, photos, lgtext, mount, lam)
    document.PricingForm.collageEstimate.value = "$" + RoundToPennies(price);
}

function GetPrice(PricingForm, height, width, photos, lgtext, mount, lam) {

        price = height * width;
        price = price / 144;
        pricetwo = price; // for lookup later
    开发者_开发技巧    price = price * 15;

        price = (PricingForm.lgtext.checked) ? price + 20 : price;
        price = (PricingForm.mount.checked) ? price + pricetwo * 5 : price;
        price = (PricingForm.lam.checked) ? price + pricetwo * 5 : price;

        return (photos * 4.95) + price;
}

function RoundToPennies(n) {
    pennies = n * 100;
    pennies = Math.round(pennies);
    strPennies = "" + pennies;
    len = strPennies.length;
    return strPennies.substring(0, len - 2) + "." + strPennies.substring(len - 2, len);
}

</script>


You don't have a mount nor a lam variables in your calculate function, I think is a copy/paste error, look:

function calculate(PricingForm) {
  //...
  mountlam = PricingForm.mount.value; // <--- the same identifier
  mountlam = PricingForm.lam.value;   // <---

  price = GetPrice(PricingForm, height, width, photos, lgtext, mount, lam);
  //..                                                           ^     ^
}

Should be:

//...
mount = PricingForm.mount.value;
lam = PricingForm.lam.value;

price = GetPrice(PricingForm, height, width, photos, lgtext, mount, lam);
//..

Also be aware that if you make an assignment without using the var statement, those variables will become global...

0

精彩评论

暂无评论...
验证码 换一张
取 消