#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    4
    Rep Power
    0

    javascript problems in IE 5.1 for mac's


    hello I am new here and would like to say hello!

    also, as you might expect, I am gonna jump right in and ask if someone can tell me why this script don't work in IE 5.1 on mac (works fine in netscape and explorer on pc and mac's).
    it is for a shopping system I am developing.

    the code is meant to add together the costs of items depening on quantity of item and where in the world they are to be shipped.



    -----------
    <SCRIPT language="JavaScript">
    <!-- hide from oldie browsers

    function defocus(x) {
    document.BuyForm.qty2.focus();
    }

    // roundOff
    // rounds off value to precision decimal places
    function roundOff(value, precision) {
    return OKStrOfMN(value,1,precision);
    }


    // OKStrOfMN
    // rounds off X to N decimal places, ensuring there are at least M leading 0's
    // http://www.merlyn.demon.co.uk/js-maths.htm
    function OKStrOfMN(X, M, N) {
    var T, S=new String(Math.round(X*Number("1e"+N)))
    while (S.length<M+N) S='0'+S
    var y = S.substr(0, T=(S.length-N));
    if(N>0) {
    y += '.' + S.substr(T, N);
    }
    return y;
    }




    function CheckNull(value) {
    if (value == "") {
    value = "0";
    }

    return value;
    }

    function typeOfCarriage(x,whereabouts) {
    x.carriage_amount.value = whereabouts;
    }

    function calculate(x) {
    basicprice = calc(x);

    if(Number(basicprice) > 0) {

    switch (x.carriage_amount.value) {
    case "uk" :
    x.postage_and_packaging.value = 0.50;
    break
    case "europe" :
    x.postage_and_packaging.value = 1.00;
    break
    default :
    x.postage_and_packaging.value = 1.50;
    break;
    }

    x.amount.value = Number(basicprice) + Number(x.postage_and_packaging.value);

    // Code to generate a dynamic description!
    x.desc.value = add_items(x);
    } else {
    x.amount.value = "0";
    }

    x.amount.value = roundOff(x.amount.value,2);

    }


    function calc(x) {
    x.amount.value = 0;
    var y = x.price.length;
    var z = x.qty.length;
    var a = Number(x.amount.value);
    var b,c,d;
    d = true;
    while(y > 0) {
    b = Number(CheckNull(x.price[y-1].value));
    c = Number(CheckNull(x.qty[y-1].value));
    if(c < 0) {
    d = false;
    c = 0;
    x.qty[y-1].value = c;
    }
    a += (b * c);
    // alert("x.price["+eval(y-1)+"].value = "+x.price[y-1].value+"\nx.qty["+eval(y-1)+"].value = "+x.qty[y-1].value+"\na = "+a);
    y--;
    }
    if(d == false) {
    alert("Negative quantities not permitted; these have been set to zero.");
    }
    a += c * 0.50;
    //alert (a);
    return a;
    }


    function add_items(x) {
    var y = x.price.length;
    var z = x.code.length;
    var d = "";
    if(y != z) alert("Missing items in form; found "+y+" occurrences of price and "+z+" of code.");
    var c = 0;
    while (c < y) {
    if(Number(CheckNull(x.qty[c].value)) > 0) {
    d += add_item(d,x.qty[c].value,x.code[c].value);

    }
    c++;
    }

    return d;
    }

    function add_item(d,q,c) {
    var r = "";
    if(d != "") {
    r += ", ";
    }
    r += q + " " + c;
    if(Number(CheckNull(q)) > 1) {
    r += "'s";
    }
    // alert("q = "+q+"\nc = "+c+"\n r = "+r);
    return r;
    }


    function validate_form(x) {
    // here is where you may wish to include more sophisticated checking, particularly of the email address.
    var e = "";
    var r = true;
    var z,n,q,t;

    t = true;
    q = 0;
    n = 0;
    z = 0;

    // alert("x.qty.length = "+x.qty.length);

    while(z < x.qty.length) {

    // alert("z = "+z);
    if(Number(CheckNull(x.qty[z].value)) < 0) {
    n++;
    } else {
    q += Number(CheckNull(x.qty[z].value));
    }
    z++;
    }

    if(n > 0) {
    e += "\nYou have entered "+n+" negative quantit";
    if(n == 1) {
    e += "y";
    } else {
    e += "ies";
    }
    r = false;
    }

    if(q == 0) {
    e += "\nYou need to select at least one item";
    r = false;
    }

    if(x.name.value == "") {
    e += "\nPlease enter a name";
    r = false;
    }

    if(x.address.value == "") {
    e += "\nPlease enter an address";
    r = false;
    }
    if(x.country.value == "") {
    e += "\nPlease select a country";
    r = false;
    }
    if(x.postcode.value == "") {
    e += "\nPlease enter a postcode or ZIP code";
    r = false;
    }
    if(x.tel.value == "") {
    e += "\nPlease enter a telephone number";
    r = false;
    }
    if(x.fax.value == "") {
    e += "\nPlease enter a fax number";
    r = false;
    }
    if(x.email.value == "") {
    e += "\nPlease enter an email address";
    r = false;
    }
    if(r == false) {
    alert("The following must be completed first:\n"+e);
    }
    return r;
    }

    // -->
    </SCRIPT>
    ----------
  2. #2
  3. No Profile Picture
    Perl Ronin
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Posts
    152
    Rep Power
    13
    Er... what error are you getting? Hard to know without the entire page (not that I"m suggesting you post the entire page, but knowing the error might prove helpful)
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    4
    Rep Power
    0
    Basically, the script takes values from input fields (quantity of items ordered) and applies functions on this to work out the total cost and shipping etc. I get a N.aN in the total box - in IE 5.1 for mac, but on every other browser I get the correct total...
    not sure why this could be.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    4
    Rep Power
    0
    -------
    function calculate(x) {
    basicprice = calc(x);

    if(Number(basicprice) > 0) {

    switch (x.carriage_amount.value) {
    case "uk" :
    x.postage_and_packaging.value = 0.50;
    break
    case "europe" :
    x.postage_and_packaging.value = 1.00;
    break
    default :
    x.postage_and_packaging.value = 1.50;
    break;
    }

    x.amount.value = Number(basicprice) + Number(x.postage_and_packaging.value);

    // Code to generate a dynamic description!
    x.desc.value = add_items(x);
    } else {
    x.amount.value = "0";
    }

    x.amount.value = roundOff(x.amount.value,2);
    alert (x.amount.value);
    }
    -----

    above is where I think the problem lies - the x.amount.value seems to be not liked in ie 5.0 and 5.1 on macs. any ideas?

IMN logo majestic logo threadwatch logo seochat tools logo