Javascript not working on MAC browsers

T

Tom Cahill

The following code will work perfectly on a PC browser, IE or Netscape.
However on a Mac browser (IE, Netscape, or Safari) it does not. I have tried
it on OSX and OS9. ANy help anyone can offer would be appreciated. Thank
you.

function calc()
{
var event1_discount_name = ""; //name of discount to be incorporated into
PayPal description
var event2_discount_name = "";

var discount_cutoff = new Date("September 10, 2004"); // Cut off date for
discounts
var today = new Date(); // Value to compare agains cut off date.
var GST_TAX = 0.07; // Current GST rate 7%

//get quantities for discounts and registrations

var event1_reg_qty = parseInt(document.REGISTER.qty.value); //Converts
quantity entered to an Integer for calculations
var event1_groupdisc_qty = parseInt(document.REGISTER.qty1.value);
var event1_tamdisc_qty = parseInt(document.REGISTER.qty8.value);

//ensure that the number of discounts is never greater than the number of
registrations

if (event1_groupdisc_qty > event1_reg_qty)
{
event1_groupdisc_qty = event1_reg_qty;
document.REGISTER.qty1.value = event1_reg_qty;
}
if (event1_tamdisc_qty > event1_reg_qty)
{
event1_tamdisc_qty = event1_reg_qty;
document.REGISTER.qty8.value = event1_reg_qty;
}

var event2_reg_qty = parseInt(document.REGISTER.qty10.value);
var event2_groupdisc_qty = parseInt(document.REGISTER.qty11.value);
var event2_tamdisc_qty = parseInt(document.REGISTER.qty12.value);

if (event2_groupdisc_qty > event2_reg_qty)
{
event2_groupdisc_qty = event2_reg_qty;
document.REGISTER.qty11.value = event2_reg_qty;
}
if (event2_tamdisc_qty > event2_reg_qty)
{
event2_tamdisc_qty = event2_reg_qty;
document.REGISTER.qty12.value = event2_reg_qty;
}

// calculate mulitple registration discount

if (event1_reg_qty > 1)
{
var event1_multidisc_qty = event1_reg_qty;
document.REGISTER.qty9.value = event1_reg_qty;

}
else var event1_multidisc_qty =0;

if (event2_reg_qty > 1)
{
var event2_multidisc_qty = event2_reg_qty;
document.REGISTER.qty13.value = event2_reg_qty;

}
else var event2_multidisc_qty =0;


var event1_sub = 0.00; //holds subtotal of event 1
var event2_sub = 0.00; // holds subtotal of event 2


var fee = 595.00; //Regular conference fee before discounts and tax

//calculate registration fee
var event1_fee = event1_reg_qty * fee;
var event2_fee = event2_reg_qty * fee;

//calculate discounts
var event1_groupdisc_sub = event1_groupdisc_qty * 60;
var event1_tamdisc_sub = event1_tamdisc_qty * 100;
var event1_multidisc_sub = event1_multidisc_qty * 60;
var event2_groupdisc_sub = event2_groupdisc_qty * 60;
var event2_tamdisc_sub = event2_tamdisc_qty * 100;
var event2_multidisc_sub = event2_multidisc_qty * 60;

//assign discount names for PayPal description

if (event1_tamdisc_qty > 0)
{
event1_discount_name = "(TAM Client)"
}
else if (event1_groupdisc_qty > 0)
{
event1_discount_name = "(CSAMUG)"
}
else event1_discount_name = "(No Discount Selected)"

if (event2_tamdisc_qty > 0)
{
event2_discount_name = "(TAM Client)"
}
else if (event2_groupdisc_qty > 0)
{
event2_discount_name = "(CSAMUG)"
}
else event2_discount_name = "(No Discount Selected)"

// only process discounts before September 10, 2004

if (today >= discount_cutoff)
{
event1_groupdisc_sub = 0;
event1_tamdisc_sub = 0;
event1_multidisc_sub = 0;
event2_groupdisc_sub = 0;
event2_tamdisc_sub = 0;
event2_multidisc_sub = 0;
event1_discount_name = "{Discounts No Longer Available)"
event1_discount_name = "{Discounts No Longer Available)"

}

//display numbers on form
document.REGISTER.sub_total.value = event1_fee.toFixed(2);
document.REGISTER.sub_total1.value = event1_groupdisc_sub.toFixed(2);
document.REGISTER.sub_total2.value = event1_tamdisc_sub.toFixed(2);
document.REGISTER.sub_total3.value = event1_multidisc_sub.toFixed(2);
document.REGISTER.sub_total6.value = event2_groupdisc_sub.toFixed(2);
document.REGISTER.sub_total7.value = event2_tamdisc_sub.toFixed(2);
document.REGISTER.sub_total8.value = event2_multidisc_sub.toFixed(2);
document.REGISTER.sub_total5.value = event2_fee.toFixed(2);

document.REGISTER.sub_total.value = "$" +
FormatCurrency(document.REGISTER.sub_total.value);
document.REGISTER.sub_total1.value = "$" + "(" +
FormatCurrency(document.REGISTER.sub_total1.value) + ")";
document.REGISTER.sub_total2.value = "$" + "(" +
FormatCurrency(document.REGISTER.sub_total2.value) + ")";
document.REGISTER.sub_total3.value = "$" + "(" +
FormatCurrency(document.REGISTER.sub_total3.value) + ")";
document.REGISTER.sub_total6.value = "$" + "(" +
FormatCurrency(document.REGISTER.sub_total6.value) + ")";
document.REGISTER.sub_total7.value = "$" + "(" +
FormatCurrency(document.REGISTER.sub_total7.value) + ")";
document.REGISTER.sub_total8.value = "$" + "(" +
FormatCurrency(document.REGISTER.sub_total8.value) + ")";
document.REGISTER.sub_total5.value = "$" +
FormatCurrency(document.REGISTER.sub_total5.value);

// If TAM discount is chosen then the CSAMUG is not applicable

if (event1_tamdisc_qty >=1)
{
event1_groupdisc_sub = 0;
document.REGISTER.sub_total1.value = "$" + "(" +
event1_groupdisc_sub.toFixed(2) + ")";
document.REGISTER.qty1.value="0";
}

// calculate and display Event 1 total

event1_sub = event1_fee - (event1_tamdisc_sub + event1_groupdisc_sub +
event1_multidisc_sub);
document.REGISTER.sub_total4.value = event1_sub.toFixed(2);
document.REGISTER.sub_total4.value = "$" +
FormatCurrency(document.REGISTER.sub_total4.value);

if (event2_tamdisc_qty >=1)
{
event2_groupdisc_sub = 0;
document.REGISTER.sub_total6.value = "$" + "(" +
event2_groupdisc_sub.toFixed(2) + ")";
document.REGISTER.qty11.value="0";
}

// calculate and display Event 2 total
event2_sub = event2_fee - (event2_tamdisc_sub + event2_groupdisc_sub +
event2_multidisc_sub);
document.REGISTER.sub_total9.value = event2_sub.toFixed(2);
document.REGISTER.sub_total9.value = "$" +
FormatCurrency(document.REGISTER.sub_total9.value);


//Calculate overall total before taxes

var sub_Total = event1_sub + event2_sub

// prevent a negative or 0 total being processed
if (sub_Total <=0)
{
if (WithoutContent(document.REGISTER.Registrant2_FirstName.value) == false)
{
document.REGISTER.qty.value=2;
document.REGISTER.Registrant2_Company.value =
document.REGISTER.Company.value
document.REGISTER.Registrant2_StreetAddress1.value =
document.REGISTER.StreetAddress1.value
document.REGISTER.Registrant2_StreetAddress2.value =
document.REGISTER.StreetAddress2.value
document.REGISTER.Registrant2_City.value = document.REGISTER.City.value
document.REGISTER.Registrant2_ProvinceState.value =
document.REGISTER.ProvinceState.value
document.REGISTER.Registrant2_PostalZipCode.value =
document.REGISTER.PostalZipCode.value
document.REGISTER.Registrant2_Phone.value = document.REGISTER.Phone.value
document.REGISTER.Registrant2_Fax.value = document.REGISTER.Fax.value

}
else
{
document.REGISTER.qty.value=1;
}

calc()
}
else
{
document.REGISTER.sub_total10.value = sub_Total.toFixed(2);
document.REGISTER.sub_total10.value = "$" +
FormatCurrency(document.REGISTER.sub_total10.value);



var tax = sub_Total * GST_TAX; //calculate the GST
var total = sub_Total + tax; // calculate the total

var description1 = "ITAM Conference Registration X " + event1_reg_qty + " "
+ event1_discount_name
var description2 = " Pre-Conference Seminar Registration X " +
event2_reg_qty + " " + event2_discount_name;

var description = description1 + description2 //Set description to be passed
to PayPal

document.REGISTER.GST.value=tax.toFixed(2); //Set the Tax field on the form
document.REGISTER.GST.value="$" +
FormatCurrency(document.REGISTER.GST.value);

document.REGISTER.TOTAL.value=total.toFixed(2); //Set the total field on the
form
document.REGISTER.TOTAL.value="$" +
FormatCurrency(document.REGISTER.TOTAL.value);
document.REGISTER.amount.value="$" + total.toFixed(2); //Set the amount to
be passed to PayPal (same value as the total field)
document.REGISTER.item_name.value=description; // Set the description to be
passed to PayPal

var timeToKeep = 7200000; // two hours
var expires = new Date();
expires.setTime(expires.getTime() + timeToKeep);
var cookie_name = "TAMcookie"
set_cookie(cookie_name, total.toFixed(2), expires);


}



}
 
L

Lasse Reichstein Nielsen

Tom Cahill said:
The following code will work perfectly on a PC browser, IE or Netscape.
However on a Mac browser (IE, Netscape, or Safari) it does not. I have tried
it on OSX and OS9.

HOW does it not work? You are missing the three R's of bug reporting:
The bug must be:
Reproducible: What must we do to reproduce the bug. You posted the
code, but not the page it depends on, so we cannot attempt to
reproduce the bug.
Recognizable: We must be able to see the bug when it happens. You
don't say how it fails, or what the normal behavior should be.
Repairable: We must know what the desired behavior is to be able
to suggest fixes.

You should also try to reduce the code to a small, self-contained
example that still exhibits the bug. Often, that procedure will
uncover the bug for yourself, and if not, it will make it much
easier to help you.

As it is, all I can offer is generalities:
var discount_cutoff = new Date("September 10, 2004"); // Cut off date for
discounts

(And make sure your lines are less than ~72 characters when posting code
to Usenet. Your news client has broken this line into two, introducing a
syntax error that wasn't in the original.)

I would not rely on how Date parses strings. It is implementation
dependent. Instead, write:
var discount_cutoff = new Date(2004, 9-1, 10);
var today = new Date(); // Value to compare agains cut off date.
var GST_TAX = 0.07; // Current GST rate 7%

//get quantities for discounts and registrations

var event1_reg_qty = parseInt(document.REGISTER.qty.value); //Converts
quantity entered to an Integer for calculations

Reading from forms is safest done using the collections:

var event1_reg_qty = parseInt(
document.forms['REGISTER'].elements['qty'].value, 10)

Since you use it all the time, I would probably define a variable:
var form = document.forms['REGISTER'].elements;
Then you can just refer to it as "form['qty'].value".

Always add the second argument (", 10") to parseInt, or someone
entering the text "020" would be surpriced to have it read as octal
(giving 16). Alteratively, use the Number function for conversion,
if you don't want to allow trailing garbage.
document.REGISTER.sub_total.value = event1_fee.toFixed(2);

the toFixed function is known to be bugged in IE 5.5 (and doesn't
exist before, which perhpas rules out Mac IE 5.2). Which is a shame,
since it's probably just what you need.
<URL:http://jibbering.com/faq/#FAQ4_6>

....
document.REGISTER.sub_total.value = "$" +
FormatCurrency(document.REGISTER.sub_total.value);

it is inefficient to first store the toFixed(2) value in the text box, and
then fetch it back again and run it through FormatCurrency. Just do it in
one go.

document.forms['REGISTER'].elements['sub_total'].value =
"$" + FormatCurrency(event1_fee.toFixed(2));

Is both toFixed and FormatCurrency really needed?
if (WithoutContent(document.REGISTER.Registrant2_FirstName.value) == false)

Just as a style hint: never compare with a boolean. Just do
if (!WithoutContent(...))

var timeToKeep = 7200000; // two hours
var expires = new Date();
expires.setTime(expires.getTime() + timeToKeep);
Or
expires.setHours(expries.getHours()+2);

var cookie_name = "TAMcookie"
set_cookie(cookie_name, total.toFixed(2), expires);

Are you sure the setting of the cookie works? We can't see
the "set_cookie" function, but try reading the cookie back
immediately and see that it is set correctly.

Good luck.
/L
 
M

Mick White

Tom said:
The following code will work perfectly on a PC browser, IE or Netscape.
However on a Mac browser (IE, Netscape, or Safari) it does not. I have tried
it on OSX and OS9. ANy help anyone can offer would be appreciated. Thank
you.

function calc(){

//display numbers on form
document.REGISTER.sub_total.value = event1_fee.toFixed(2);

Number.toFixed() method not implemented on most Mac browsers (JS 1.5)

Mick
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
(And make sure your lines are less than ~72 characters when posting code
to Usenet. Your news client has broken this line into two, introducing a
syntax error that wasn't in the original.)

The requirement is that the posting agent should not break code lines.
That does not necessarily imply that the lines must be shorter than 72
(though it may do so in, perhaps, OE). While code should not be posted
very wide, it should be entirely OK to post lines of 78 unbroken.


I would not rely on how Date parses strings.

It seems safe if the month uses letters and the year has four digits, or
if Y/M/D order is used.
It is implementation
dependent. Instead, write:
var discount_cutoff = new Date(2004, 9-1, 10);

But that is infallible.

Or
expires.setHours(expries.getHours()+2);

That does change the meaning slightly, though. The original changes the
actual time, the revision changes the clock time. You might try the
following for B=0 & B=1 :-
B = 1
D = new Date(1099182600000) // 2004-10-31 Sun 00:30:00 GMT.
B ? D.setHours(D.getHours()+2) : D.setTime(D.getTime()+72e5)
D
In this case, elapsed time is probably more important than clock time;
it would be otherwise if the delay were a day or more.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top