Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Java script error script works but still get error

    I have a javascript that functions properly but I get an error at the bottom of browser in IE

    Here is the script

    Code:
    <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
    Code:
    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
    Last edited by mestes; 12-17-2004 at 12:13 AM.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank You Very Much.

    I apppreciate the help.

    Works great now.


  •  

    Posting Permissions

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