Forum Moderators: travelin cat

Message Too Old, No Replies

Javascript not working on web page on a Mac

Javascript not working on web page on a Mac - it is OK in IE on a PC

         

garrybrown

2:36 pm on Apr 15, 2005 (gmt 0)

10+ Year Member



Hi all

I would really appreciate anybodys assistance on this matter.

I have recently uploaded a website.

On the Prescription Page (search for an item, add to basket, Enter prescription - actually called lens.asp) the end price is calculated using client side javascript which stores the result in a hidden form field.

One of our customers has reported that the total does not recalculate for them - they are using a Mac with IE and Safari - both browsers have the same issue.

The problem I have is that if the total does not get calculated OK, the final payment taken is incorrect.

Can someone help me either by looking at the site via a Mac and letting me know the errors reported (I am assuming that there are client side script alerts), or having a quick look at the javascript in the source refreshPrice() and submitForm() and letting me know if I am being a muppet.

Thanks in advance.

Garry

[edited by: engine at 2:53 pm (utc) on April 15, 2005]
[edit reason] No urls, thanks. See TOS [webmasterworld.com] [/edit]

whoisgregg

2:47 pm on Apr 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, garrybrown!

The problem I have is that if the total does not get calculated OK, the final payment taken is incorrect.

First off, never trust your client side javascripts to return trustable order totals. Users can completely disable javascript, partially disable it, or actually change parts of the javascript in certain browsers. We should be able to fix your javascript but ultimately, your server side processing needs to look for these problems and correct them.

That said, 90% of the time this problem arises (javascript order totals won't work) it's because the code is using .toFixed(2) which is not widely supported. Even in browsers that support it, there are reports of flaky results.

Check your code for this, replace it with your own rounding function and let us know if it's still broken. :)

Also, post the relevant sections of code as WebmasterWorld frowns upon personal URL drops. (Although you are welcome to use the board's stickymail to send URL's to other members.)

garrybrown

3:25 pm on Apr 15, 2005 (gmt 0)

10+ Year Member



Thanks for your comments and the heads up on personal URL's.

Here is the refreshPrice() code which is causing me issues:-

function refreshPrice()
{
var price=49.99;

if (document.PAYMENT.LENSOPTION.value=='PRESCRIPTION FREE (FREE)')
{
price = price;
}

else if (document.PAYMENT.LENSOPTION.options(document.PAYMENT.LENSOPTION.selectedIndex).value=='SINGLE VISION (FREE)')
{
price = price;
}

else if (document.PAYMENT.LENSOPTION.options(document.PAYMENT.LENSOPTION.selectedIndex).value=='THINNER 1.6 (+£35)')
{
price = price + 35;
}

else if (document.PAYMENT.LENSOPTION.options(document.PAYMENT.LENSOPTION.selectedIndex).value=='THINNER 1.67 (+£40)')
{
price = price + 40;
}

if (document.PAYMENT.LENSUSE.options(document.PAYMENT.LENSUSE.selectedIndex).value=='BIFOCAL (+£15)')
{
price = price + 15;
}

if (document.PAYMENT.TINTOPTION.options(document.PAYMENT.TINTOPTION.selectedIndex).value=='BROWN TINT (+£10)')
{
price = price + 10;
}

else if (document.PAYMENT.TINTOPTION.options(document.PAYMENT.TINTOPTION.selectedIndex).value=='GREY TINT (+£10)')
{
price = price + 10;
}

if (document.PAYMENT.TRANSITION.checked==true)
{
price = price + 45;
}

if (document.PAYMENT.ANTIREFLECTIVE.checked==true)
{
price = price + 25;
}

document.PAYMENT.PRICE.value="TOTAL PRICE: £"+price+"";
document.PAYMENT.ITEM_PRICE.value=""+price+"";
}

As an example of a single drop down which triggers this:-

<form NAME="PAYMENT" METHOD="POST" Action="lens.asp">

<input type="hidden" name="ITEM_PRICE" value="49.99">

<SELECT NAME="LENSOPTION" onChange="refreshPrice();">
<OPTION SELECTED value="">Select Lens Option</OPTION>
<OPTION value="PRESCRIPTION FREE (FREE)">Prescription Free Lenses (FREE)</OPTION>
<OPTION value="SINGLE VISION (FREE)">Single Vision (FREE)</OPTION>
<OPTION value="THINNER 1.6 (+£35)">Thinner 1.6 Lenses (+£35)</OPTION>
<OPTION value="THINNER 1.67 (+£40)">Thinner 1.67 Lenses (+£40)</OPTION>
</SELECT>

At your suggestion I have removed the .toFixed - rounding is the least of my problems at the moment :-)

whoisgregg

4:30 pm on Apr 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It looks like that has it working now. BTW, you probably want to explicitly declare that you are using UTF-8 encoding, with a meta tag like this:
<meta http-equiv="content-type" content="text/html; charset=utf-8">

Rounding is pretty straightforward:
price = ((Math.round(price*100))/100);

Since all your pricing ends in .99 anyways, you don't even have to worry about adding extra zeros at the end. If you did, there are excellent "javascript currency format functions" out there. :)

garrybrown

8:10 am on Apr 18, 2005 (gmt 0)

10+ Year Member



Excellent - thanks for your help!