...

View Full Version : Java script error script works but still get error



mestes
12-13-2004, 04:50 AM
I have a javascript that functions properly but I get an error at the bottom of browser in IE

Here is the script



<script language="JavaScript" type="text/JavaScript">

<!--

function settax(Info){

if(Info.state.value == ""){return false;}<<<---Line 25 from error code

if(Info.state.value == "MA"){

Info.tax.value = 5;

}else{

Info.tax.value = 0;
}

recalculate(Info);

return false;

}

function recalculate(Info){
var qty = parseInt(Info.qty.value);
if(isNaN(qty)) qty = 0;
var price = parseFloat(Info.price.value);
var shiphand = parseFloat(Info.shiphand.value);
var shiphand = 3.00;
var tax = parseFloat(Info.tax.value) * .01;

price *= qty;
shiphand = (qty > 1)?(shiphand + ((qty - 1) * 1.5)):(qty == 1)?(shiphand):(0);
tax *= price;

Info.shiphand.value = (3.00 + ((Info.qty.value - 1) * 1.50)).toFixed(2);

Info.total.value = (price + tax + shiphand).toFixed(2);
}
//-->

onLoad = settax(document.buynow);

</script>


The error in IE reads like this


Line: 25
Char:2
Error:'state' is not null or not an object
Code:0
URL:


Now in the script above I labeled line 25 of the script.

Can anyone tell me how to keep the script working but not have that error.

Thanks

glenngv
12-13-2004, 05:14 AM
Change this:

onLoad = settax(document.buynow);

to:

window.onload = function(){settax(document.buynow)};

The error occurs because settax() is called before the form has loaded. Your original onload line calls the settax() function and not set it to the handler.

mestes
12-13-2004, 07:00 AM
Thank You Very Much.

I apppreciate the help.

Works great now.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum