Jump to content

Another Firefox js error


M.O.S. Studios

Recommended Posts

Hey Guys,

I tired this script in ie, safari, ff (mac) and(pc), it worked in all of them except ff(pc).

firefox isn't give me any error codes and the other javascripts on the same page work fine. that being said i have canceled out the js being disabled, also i tried it on another pc with ff and it isn't workingtheir either.

 

here is the script:

header:

<script language="javascript" type="text/javascript"> 
function Calculate()
{
    with(document.forms['myform'].elements)
    {
        Cost1.value = parseFloat(Qty1.value) * parseFloat(Price1.value);
Cost2.value = parseFloat(Qty2.value) * parseFloat(Price2.value);
var subTotal = parseFloat(Cost1.value) + parseFloat(Cost2.value);        subtotal.value = subTotal;
    }
if (myform.Qty1.value != 0){var catvalue1 = (parseFloat(myform.Qty1.value) * 2);}else{var catvalue1 = 0;}
if (myform.Qty2.value != 0){var catvalue2 = (parseFloat(myform.Qty2.value) * 5);}else{var catvalue2 = 0;}

var catvalue = parseFloat(catvalue1) + parseFloat(catvalue2);
var nop = parseFloat(myform.Qty1.value) + parseFloat(myform.Qty2.value);
if (myform.Qty1.value != 0){var nos = nos+1;}else{var nos = nos-1;}if (myform.Qty2.value != 0){var nos = nos+1;}else{var nos = nos-1;}
if (myform.taxes_cost.value == 1){
var tax1 = subTotal * 0.05;
myform.taxname1.value = 'G.s.t';
myform.taxname2.value = 'P.s.t';
var tax2 = (subTotal+parseFloat(tax1)) * 0.075;
myform.taxname3.value = 'F.s.t';
var tax3 = (subTotal+parseFloat(tax1)+parseFloat(tax2)) * 0.03;
}

if (myform.taxes_cost.value == 2){
var tax1 = subTotal * 0.05;
myform.taxname1.value = 'G.s.t';
myform.taxname2.value = 'P.s.t';
var tax2 = subTotal * 0.075;
var tax3 = 0;
myform.taxname3.value = '';
}

if (myform.ship_cost.value == 1){var shipping =(parseFloat(myform.subtotal.value)*(10/100));}
if (myform.ship_cost.value == 2){var shipping =(20);}
if (myform.ship_cost.value == 4){var shipping =catvalue;}

myform.shipping.value = shipping.toFixed(2);

myform.tax1.value = tax1.toFixed(2);
myform.tax2.value = tax2.toFixed(2);
myform.tax3.value = tax3.toFixed(2);

var totalValue = parseFloat(myform.subtotal.value) + parseFloat(myform.shipping.value)  + parseFloat(tax1) + parseFloat(tax2) + parseFloat(tax3);
myform.total.value =  totalValue.toFixed(2);
    return;

}
</script>

 

body

 

<form NAME="myform" method="POST" action="account.php?actions=altsales">
<br><br>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr width='100%' height='50'><td align='center' width='20%'>ITEM NAME</td><td align='center' width='10%'>ITEM NUMBER</td><td align='center' width='20%'>CATAGORY</td><td align='center' width='10%'>QTY ORDERED</td><td align='center' width='10%'>QTY</td><td align='center' width='10%'>PRICE</td><td align='center' width='20%'>TOTAL AMOUNT</td></tr>
  <tr width='100%'><td align='center' width='20%'>Small Dichroic Pendant</td><td align='center' width='10%'>D087</td><td align='center' width='20%'>Dichroic</td><td align='center' width='10%'>1</td><td align='center' width='10%'><select NAME='Qty1' onChange='Calculate();'><option value='0' >0</option><option value='1' SELECTED>1</option></select></td><td align='center' width='10%'><INPUT TYPE='TEXT' SIZE='5' name='Price1' value='15.00' Readonly></td><td align='center' width='20%'><INPUT TYPE='TEXT' NAME='Cost1' SIZE='8' READONLY></td></tr>
<tr width='100%'><td align='center' width='20%'>Lapis Around You</td><td align='center' width='10%'>B120</td><td align='center' width='20%'>Necklaces</td><td align='center' width='10%'>1</td><td align='center' width='10%'><select NAME='Qty2' onChange='Calculate();'><option value='0' >0</option><option value='1' SELECTED>1</option></select></td><td align='center' width='10%'><INPUT TYPE='TEXT' SIZE='5' name='Price2' value='18.00' Readonly></td><td align='center' width='20%'><INPUT TYPE='TEXT' NAME='Cost2' SIZE='8' READONLY></td></tr>
<tr width='100%' height='50'><td align='center' width='20%'></td><td align='center' width='10%'></td><td align='center' width='20%'></td><td align='center' width='10%'></td><td align='center' width='10%'></td><td align='center' width='10%'></td><td align='right' width='20%'>Subtotal: <INPUT TYPE="TEXT" NAME="subtotal" SIZE="8" onChange='Calculate();' READONLY></td></tr>
<tr width='100%' height='50'><td align='right' width='20%'></td><td align='right' width='10%'></td><td align='right' width='20%'></td><td align='right' width='10%'></td><td align='right' width='10%'></td>
<td align='right' width='10%'>

Shipping Cost
<select name='ship_cost' onChange='Calculate();'>
<option value='1'>Canada</option><option value='2'>United States</option><option value='4'>MEXICO</option></select>

<br>
<br>

Taxes Cost
<select name='taxes_cost' onChange='Calculate();'>
<option value='1'>Quebec</option><option value='2'>Ontario</option></select>

</td><td align='right' width='20%'>

Shipping: <INPUT TYPE="TEXT" value="" NAME="shipping" SIZE="8" READONLY>
<br><INPUT TYPE="TEXT" value="" NAME="taxname1" SIZE="5" READONLY>: <INPUT TYPE="TEXT" value="" NAME="tax1" SIZE="8" READONLY>
<br><INPUT TYPE="TEXT" value="" NAME="taxname2" SIZE="5" READONLY>: <INPUT TYPE="TEXT" value="" NAME="tax2" SIZE="8" READONLY>
<br><INPUT TYPE="TEXT" value="" NAME="taxname3" SIZE="5" READONLY>: <INPUT TYPE="TEXT" value="" NAME="tax3" SIZE="8" READONLY>
<br>Total: <INPUT TYPE="TEXT" NAME="total" SIZE="8" onChange='Calculate();' READONLY></td></tr>
</table>
</form>

 

any ideas??

 

 

thanks in advance

Link to comment
Share on other sites

should use !== instead of !=

 

warning: redeclaration of var nos

 

warning: redeclaration of var tax1

 

warning: redeclaration of var tax2

warning: redeclaration of var shipping

 

lint warning: with statement hides undeclared variables; use temporary variable instead

 

warning: redeclaration of var catvalue1

 

warning: redeclaration of var catvalue2

Link to comment
Share on other sites

Fixed up redeclaration of variable errors & changed with to while:

function Calculate()
{
    while(document.forms['myform'].elements)
    {
        Cost1.value = parseFloat(Qty1.value) * parseFloat(Price1.value);
Cost2.value = parseFloat(Qty2.value) * parseFloat(Price2.value);
var subTotal = parseFloat(Cost1.value) + parseFloat(Cost2.value);        subtotal.value = subTotal;
    }
if (myform.Qty1.value !== 0){var catvalue1 = (parseFloat(myform.Qty1.value) * 2);}else{ catvalue1 = 0;}
if (myform.Qty2.value !== 0){var catvalue2 = (parseFloat(myform.Qty2.value) * 5);}else{ catvalue2 = 0;}

var catvalue = parseFloat(catvalue1) + parseFloat(catvalue2);
var nop = parseFloat(myform.Qty1.value) + parseFloat(myform.Qty2.value);
if (myform.Qty1.value !== 0){var nos = nos+1;}else{ nos = nos-1;}if (myform.Qty2.value !== 0){ nos = nos+1;}else{nos = nos-1;}
if (myform.taxes_cost.value == 1){
var tax1 = subTotal * 0.05;
myform.taxname1.value = 'G.s.t';
myform.taxname2.value = 'P.s.t';
var tax2 = (subTotal+parseFloat(tax1)) * 0.075;
myform.taxname3.value = 'F.s.t';
var tax3 = (subTotal+parseFloat(tax1)+parseFloat(tax2)) * 0.03;
}

if (myform.taxes_cost.value === 2){
tax1 = subTotal * 0.05;
myform.taxname1.value = 'G.s.t';
myform.taxname2.value = 'P.s.t';
tax2 = subTotal * 0.075;
tax3 = 0;
myform.taxname3.value = '';
}

if (myform.ship_cost.value === 1){var shipping =(parseFloat(myform.subtotal.value)*(10/100));}
if (myform.ship_cost.value === 2){ shipping =(20);}
if (myform.ship_cost.value === 4){ shipping =catvalue;}

myform.shipping.value = shipping.toFixed(2);

myform.tax1.value = tax1.toFixed(2);
myform.tax2.value = tax2.toFixed(2);
myform.tax3.value = tax3.toFixed(2);

var totalValue = parseFloat(myform.subtotal.value) + parseFloat(myform.shipping.value)  + parseFloat(tax1) + parseFloat(tax2) + parseFloat(tax3);
myform.total.value =  totalValue.toFixed(2);
    return;

}

Link to comment
Share on other sites

Fixed dot notation error:

function Calculate()
{
    while(document.forms('myform').elements)
    {
        Cost1.value = parseFloat(Qty1.value) * parseFloat(Price1.value);
Cost2.value = parseFloat(Qty2.value) * parseFloat(Price2.value);
var subTotal = parseFloat(Cost1.value) + parseFloat(Cost2.value);        subtotal.value = subTotal;
    }
if (myform.Qty1.value !== 0){var catvalue1 = (parseFloat(myform.Qty1.value) * 2);}else{ catvalue1 = 0;}
if (myform.Qty2.value !== 0){var catvalue2 = (parseFloat(myform.Qty2.value) * 5);}else{ catvalue2 = 0;}

var catvalue = parseFloat(catvalue1) + parseFloat(catvalue2);
var nop = parseFloat(myform.Qty1.value) + parseFloat(myform.Qty2.value);
if (myform.Qty1.value !== 0){var nos = nos+1;}else{ nos = nos-1;}if (myform.Qty2.value !== 0){ nos = nos+1;}else{nos = nos-1;}
if (myform.taxes_cost.value == 1){
var tax1 = subTotal * 0.05;
myform.taxname1.value = 'G.s.t';
myform.taxname2.value = 'P.s.t';
var tax2 = (subTotal+parseFloat(tax1)) * 0.075;
myform.taxname3.value = 'F.s.t';
var tax3 = (subTotal+parseFloat(tax1)+parseFloat(tax2)) * 0.03;
}

if (myform.taxes_cost.value === 2){
tax1 = subTotal * 0.05;
myform.taxname1.value = 'G.s.t';
myform.taxname2.value = 'P.s.t';
tax2 = subTotal * 0.075;
tax3 = 0;
myform.taxname3.value = '';
}

if (myform.ship_cost.value === 1){var shipping =(parseFloat(myform.subtotal.value)*(10/100));}
if (myform.ship_cost.value === 2){ shipping =(20);}
if (myform.ship_cost.value === 4){ shipping =catvalue;}

myform.shipping.value = shipping.toFixed(2);

myform.tax1.value = tax1.toFixed(2);
myform.tax2.value = tax2.toFixed(2);
myform.tax3.value = tax3.toFixed(2);

var totalValue = parseFloat(myform.subtotal.value) + parseFloat(myform.shipping.value)  + parseFloat(tax1) + parseFloat(tax2) + parseFloat(tax3);
myform.total.value =  totalValue.toFixed(2);
    return;

}

Link to comment
Share on other sites

hey, i tried both of those scripts and they didn't work.

 

this is the script i tried myself, some of the values changed but the script is the same.

 


function Calculate()
{
var subTotal = 0;
var nos=2;
var nop = parseFloat(myform.Qty1.value) + parseFloat(myform.Qty2.value);
var tax1 = 0;
var catvalue = 0;
var tax2 = 0;
var tax3 = 0;
var shipping=0;

    with(document.forms['myform'].elements)
    {
        Cost1.value = parseFloat(Qty1.value) * parseFloat(Price1.value);
Cost2.value = parseFloat(Qty2.value) * parseFloat(Price2.value);

subTotal = parseFloat(Cost1.value) + parseFloat(Cost2.value);
        subtotal.value = subTotal;
    }
var catvalue1 = 0;
if (myform.Qty1.value !== 0){catvalue1 = (parseFloat(myform.Qty1.value) * 5);}
var catvalue2 = 0;
if (myform.Qty2.value !== 0){catvalue2 = (parseFloat(myform.Qty2.value) * 5);}

catvalue = parseFloat(catvalue1) + parseFloat(catvalue2);if (myform.Qty1.value == 0){nos = nos-1;}if (myform.Qty2.value == 0){nos = nos-1;}
if (myform.taxes_cost.value == 1){
tax1 = subTotal * 0.05;
myform.taxname1.value = 'G.s.t';
myform.taxname2.value = 'P.s.t';
tax2 = (subTotal+parseFloat(tax1)) * 0.075;
myform.taxname3.value = 'F.s.t';
tax3 = (subTotal+parseFloat(tax1)+parseFloat(tax2)) * 0.03;
}

if (myform.taxes_cost.value == 2){
tax1 = subTotal * 0.05;
myform.taxname1.value = 'G.s.t';
myform.taxname2.value = 'P.s.t';
tax2 = subTotal * 0.075;
myform.taxname3.value = '';
}


if (myform.ship_cost.value == 1){shipping =(parseFloat(myform.subtotal.value)*(10/100));}
if (myform.ship_cost.value == 2){shipping =(parseFloat(nos));}
if (myform.ship_cost.value == 4){shipping =catvalue;}


myform.shipping.value = shipping.toFixed(2);

myform.tax1.value = tax1.toFixed(2);
myform.tax2.value = tax2.toFixed(2);
myform.tax3.value = tax3.toFixed(2);

var totalValue = parseFloat(myform.subtotal.value) + parseFloat(myform.shipping.value)  + parseFloat(tax1) + parseFloat(tax2) + parseFloat(tax3);
myform.total.value =  totalValue.toFixed(2);
    return;

}


 

it didn't work either.

 

it is really weird that it works on the mac version, but not the pc version.

Link to comment
Share on other sites

  • 3 weeks later...

hey i it took a while for me to reply, but to answer your question, no i cannot provide a link because it contains clients personal info.

 

how ever, i did some research, and it looks like the problem is here

 

var nop = parseFloat(myform.Qty1.value) + parseFloat(myform.Qty2.value);

 

firefox likes it more when it uses the GetElementbyId() or GetElementbyName() opposed to the "myform.Qty1.value" way

 

im not quite sure how to phrase this, any one know how to?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.