Javascript not working on MAC browsers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom Cahill

    Javascript not working on MAC browsers

    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(docume nt.REGISTER.qty .value); //Converts
    quantity entered to an Integer for calculations
    var event1_groupdis c_qty = parseInt(docume nt.REGISTER.qty 1.value);
    var event1_tamdisc_ qty = parseInt(docume nt.REGISTER.qty 8.value);

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

    if (event1_groupdi sc_qty > event1_reg_qty)
    {
    event1_groupdis c_qty = event1_reg_qty;
    document.REGIST ER.qty1.value = event1_reg_qty;
    }
    if (event1_tamdisc _qty > event1_reg_qty)
    {
    event1_tamdisc_ qty = event1_reg_qty;
    document.REGIST ER.qty8.value = event1_reg_qty;
    }

    var event2_reg_qty = parseInt(docume nt.REGISTER.qty 10.value);
    var event2_groupdis c_qty = parseInt(docume nt.REGISTER.qty 11.value);
    var event2_tamdisc_ qty = parseInt(docume nt.REGISTER.qty 12.value);

    if (event2_groupdi sc_qty > event2_reg_qty)
    {
    event2_groupdis c_qty = event2_reg_qty;
    document.REGIST ER.qty11.value = event2_reg_qty;
    }
    if (event2_tamdisc _qty > event2_reg_qty)
    {
    event2_tamdisc_ qty = event2_reg_qty;
    document.REGIST ER.qty12.value = event2_reg_qty;
    }

    // calculate mulitple registration discount

    if (event1_reg_qty > 1)
    {
    var event1_multidis c_qty = event1_reg_qty;
    document.REGIST ER.qty9.value = event1_reg_qty;

    }
    else var event1_multidis c_qty =0;

    if (event2_reg_qty > 1)
    {
    var event2_multidis c_qty = event2_reg_qty;
    document.REGIST ER.qty13.value = event2_reg_qty;

    }
    else var event2_multidis c_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_groupdis c_sub = event1_groupdis c_qty * 60;
    var event1_tamdisc_ sub = event1_tamdisc_ qty * 100;
    var event1_multidis c_sub = event1_multidis c_qty * 60;
    var event2_groupdis c_sub = event2_groupdis c_qty * 60;
    var event2_tamdisc_ sub = event2_tamdisc_ qty * 100;
    var event2_multidis c_sub = event2_multidis c_qty * 60;

    //assign discount names for PayPal description

    if (event1_tamdisc _qty > 0)
    {
    event1_discount _name = "(TAM Client)"
    }
    else if (event1_groupdi sc_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_groupdi sc_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_groupdis c_sub = 0;
    event1_tamdisc_ sub = 0;
    event1_multidis c_sub = 0;
    event2_groupdis c_sub = 0;
    event2_tamdisc_ sub = 0;
    event2_multidis c_sub = 0;
    event1_discount _name = "{Discounts No Longer Available)"
    event1_discount _name = "{Discounts No Longer Available)"

    }

    //display numbers on form
    document.REGIST ER.sub_total.va lue = event1_fee.toFi xed(2);
    document.REGIST ER.sub_total1.v alue = event1_groupdis c_sub.toFixed(2 );
    document.REGIST ER.sub_total2.v alue = event1_tamdisc_ sub.toFixed(2);
    document.REGIST ER.sub_total3.v alue = event1_multidis c_sub.toFixed(2 );
    document.REGIST ER.sub_total6.v alue = event2_groupdis c_sub.toFixed(2 );
    document.REGIST ER.sub_total7.v alue = event2_tamdisc_ sub.toFixed(2);
    document.REGIST ER.sub_total8.v alue = event2_multidis c_sub.toFixed(2 );
    document.REGIST ER.sub_total5.v alue = event2_fee.toFi xed(2);

    document.REGIST ER.sub_total.va lue = "$" +
    FormatCurrency( document.REGIST ER.sub_total.va lue);
    document.REGIST ER.sub_total1.v alue = "$" + "(" +
    FormatCurrency( document.REGIST ER.sub_total1.v alue) + ")";
    document.REGIST ER.sub_total2.v alue = "$" + "(" +
    FormatCurrency( document.REGIST ER.sub_total2.v alue) + ")";
    document.REGIST ER.sub_total3.v alue = "$" + "(" +
    FormatCurrency( document.REGIST ER.sub_total3.v alue) + ")";
    document.REGIST ER.sub_total6.v alue = "$" + "(" +
    FormatCurrency( document.REGIST ER.sub_total6.v alue) + ")";
    document.REGIST ER.sub_total7.v alue = "$" + "(" +
    FormatCurrency( document.REGIST ER.sub_total7.v alue) + ")";
    document.REGIST ER.sub_total8.v alue = "$" + "(" +
    FormatCurrency( document.REGIST ER.sub_total8.v alue) + ")";
    document.REGIST ER.sub_total5.v alue = "$" +
    FormatCurrency( document.REGIST ER.sub_total5.v alue);

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

    if (event1_tamdisc _qty >=1)
    {
    event1_groupdis c_sub = 0;
    document.REGIST ER.sub_total1.v alue = "$" + "(" +
    event1_groupdis c_sub.toFixed(2 ) + ")";
    document.REGIST ER.qty1.value=" 0";
    }

    // calculate and display Event 1 total

    event1_sub = event1_fee - (event1_tamdisc _sub + event1_groupdis c_sub +
    event1_multidis c_sub);
    document.REGIST ER.sub_total4.v alue = event1_sub.toFi xed(2);
    document.REGIST ER.sub_total4.v alue = "$" +
    FormatCurrency( document.REGIST ER.sub_total4.v alue);

    if (event2_tamdisc _qty >=1)
    {
    event2_groupdis c_sub = 0;
    document.REGIST ER.sub_total6.v alue = "$" + "(" +
    event2_groupdis c_sub.toFixed(2 ) + ")";
    document.REGIST ER.qty11.value= "0";
    }

    // calculate and display Event 2 total
    event2_sub = event2_fee - (event2_tamdisc _sub + event2_groupdis c_sub +
    event2_multidis c_sub);
    document.REGIST ER.sub_total9.v alue = event2_sub.toFi xed(2);
    document.REGIST ER.sub_total9.v alue = "$" +
    FormatCurrency( document.REGIST ER.sub_total9.v alue);


    //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.REGIS TER.Registrant2 _FirstName.valu e) == false)
    {
    document.REGIST ER.qty.value=2;
    document.REGIST ER.Registrant2_ Company.value =
    document.REGIST ER.Company.valu e
    document.REGIST ER.Registrant2_ StreetAddress1. value =
    document.REGIST ER.StreetAddres s1.value
    document.REGIST ER.Registrant2_ StreetAddress2. value =
    document.REGIST ER.StreetAddres s2.value
    document.REGIST ER.Registrant2_ City.value = document.REGIST ER.City.value
    document.REGIST ER.Registrant2_ ProvinceState.v alue =
    document.REGIST ER.ProvinceStat e.value
    document.REGIST ER.Registrant2_ PostalZipCode.v alue =
    document.REGIST ER.PostalZipCod e.value
    document.REGIST ER.Registrant2_ Phone.value = document.REGIST ER.Phone.value
    document.REGIST ER.Registrant2_ Fax.value = document.REGIST ER.Fax.value

    }
    else
    {
    document.REGIST ER.qty.value=1;
    }

    calc()
    }
    else
    {
    document.REGIST ER.sub_total10. value = sub_Total.toFix ed(2);
    document.REGIST ER.sub_total10. value = "$" +
    FormatCurrency( document.REGIST ER.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.REGIST ER.GST.value=ta x.toFixed(2); //Set the Tax field on the form
    document.REGIST ER.GST.value="$ " +
    FormatCurrency( document.REGIST ER.GST.value);

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

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


    }



    }


  • Lasse Reichstein Nielsen

    #2
    Re: Javascript not working on MAC browsers

    "Tom Cahill" <nospam@nowau.c om> writes:
    [color=blue]
    > 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.[/color]

    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:
    [color=blue]
    > var discount_cutoff = new Date("September 10, 2004"); // Cut off date for
    > discounts[/color]

    (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);
    [color=blue]
    > 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(docume nt.REGISTER.qty .value); //Converts
    > quantity entered to an Integer for calculations[/color]

    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.
    [color=blue]
    > document.REGIST ER.sub_total.va lue = event1_fee.toFi xed(2);[/color]

    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>

    ....[color=blue]
    > document.REGIST ER.sub_total.va lue = "$" +
    > FormatCurrency( document.REGIST ER.sub_total.va lue);[/color]

    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.toFi xed(2));

    Is both toFixed and FormatCurrency really needed?
    [color=blue]
    > if (WithoutContent (document.REGIS TER.Registrant2 _FirstName.valu e) == false)[/color]

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

    [color=blue]
    > var timeToKeep = 7200000; // two hours
    > var expires = new Date();
    > expires.setTime (expires.getTim e() + timeToKeep);[/color]

    Or
    expires.setHour s(expries.getHo urs()+2);
    [color=blue]
    > var cookie_name = "TAMcookie"
    > set_cookie(cook ie_name, total.toFixed(2 ), expires);[/color]

    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
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Mick White

      #3
      Re: Javascript not working on MAC browsers

      Tom Cahill wrote:
      [color=blue]
      > 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(){[/color]

      [color=blue]
      > //display numbers on form
      > document.REGIST ER.sub_total.va lue = event1_fee.toFi xed(2);[/color]

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

      Mick

      Comment

      • Dr John Stockton

        #4
        Re: Javascript not working on MAC browsers

        JRS: In article <7ju083yq.fsf@h otpop.com>, seen in
        news:comp.lang. javascript, Lasse Reichstein Nielsen <lrn@hotpop.com >
        posted at Tue, 22 Jun 2004 09:08:29 :
        [color=blue]
        >(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.)[/color]

        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.


        [color=blue]
        >I would not rely on how Date parses strings.[/color]

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

        But that is infallible.

        [color=blue][color=green]
        >> var timeToKeep = 7200000; // two hours
        >> var expires = new Date();
        >> expires.setTime (expires.getTim e() + timeToKeep);[/color]
        >
        >Or
        > expires.setHour s(expries.getHo urs()+2);[/color]

        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(1099182600 000) // 2004-10-31 Sun 00:30:00 GMT.
        B ? D.setHours(D.ge tHours()+2) : D.setTime(D.get Time()+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.

        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
        Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
        PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
        Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

        Comment

        Working...