www.webdeveloper.com
Results 1 to 4 of 4

Thread: Quick browser problem

Hybrid View

  1. #1
    Join Date
    Mar 2005
    Location
    Western USA
    Posts
    198

    Quick browser problem

    This javascript works great in IE. But won't run in netscape or FF. In the page it is called by onBlur and onClick in two different places. I don't know much about the different browsers, but is there something that jumps out in the code that isn't compatable?

    function screen() {

    var subject=document.forms.orderform_16180;
    var x = subject.amount.value;
    var y = "Incomplete data";
    var total = document.forms.formjunk.product_options_amountzz.value;
    var my_select = document.getElementById("product_options_colorzz");
    var my_selectz = document.getElementById("product_options_Sizezz");
    var opts = my_select.options;
    var optsz = my_selectz.options;
    var choice = my_select.selectedIndex;
    var choicez = my_selectz.selectedIndex;
    var value = my_select.options[my_select.selectedIndex].value;
    var valuez = my_selectz.options[my_selectz.selectedIndex].value;
    var htextra = document.forms.myform.total.value;
    var ssextraf = document.forms.myform.sscolorfront.value;
    var ssextrab = document.forms.myform.sscolorback.value;
    var ssextrar = document.forms.myform.sscolorright.value;
    var ssextral = document.forms.myform.sscolorleft.value;
    var ssextra = (ssextraf) - (-ssextrab) - (-ssextrar) - (-ssextral);
    //var white = document.forms.formjunk.product_options_colorzz.0;
    if (1<=x && x<=20) y=(0.0524*x*x)-(2.1391*x)+(32.04575);
    if (20<x && x<=50) y=39.779 * Math.pow(x, -0.4532);
    if (50<x && x<=288) y=(10.4835 * Math.pow(x, -0.121635))+.2;
    if (288<x && x<=4200) y=(10.4835 * Math.pow(x, -0.121635))+.2;
    if (4200<x) y=4;

    document.forms.orderform_16180.amount.value = total;
    subject.price.value = ((Math.round((y - (-htextra - ssextra)) *100)/100).toFixed(2)) ;
    subject.subtotal.value = ((Math.round(subject.price.value * x*100)/100).toFixed(2));

    if (opts[choice].value == 'white') subject.lightshirts.value = total;
    else subject.lightshirts.value = "0";
    if (valuez == 'xlarge') subject.bigshirts.value = total;
    else subject.bigshirts.value = "0";
    subject.totalcost.value = ((Math.round((subject.subtotal.value - subject.lightshirts.value - (subject.bigshirts.value * -1))*100)/100).toFixed(2));
    }

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Could be this forms array :
    document.forms.orderform_16180;
    Change to:
    document.forms['orderform_16180'];
    and all others
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    May 2004
    Location
    Manhattan NY
    Posts
    6,028
    What Fang said. Unless your form is named "forms" that code is incorrect. You either reference it by name, and use dot notation as you have it there, or you use forms[0], if it's the 1st or only form, or you do what Fang posted.

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    when using special characters in names (_ , - , and so on) or when you need a dynamically change (or loop), use the full square brackets notation

    document.forms['formname'].elements['elementname']

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles