Reply
Code is not executing in Opera, Mozilla/FireFox or on a MAC.
Old 12-18-2004, 02:00 PM Code is not executing in Opera, Mozilla/FireFox or on a MAC.
Webmaster Talker

Posts: 554
Hello,

I have a calculation function on my website that I am trying to call. For some reason it is working in IE and not in Opera, FireFox or on a MAC.

Could someone look at it and tell me why?

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>rsptime.ca: The financial choice, in plain english! - (866) 257-0158 - Progressive Tax</title>
<script type="text/javascript" language="javascript">
function ChangeClass(menu, newClass) { 
	 if (document.getElementById) { 
	 	document.getElementById(menu).className = newClass
 	 }
}

function RoundDollar(amt, decimals)
{
	var result1 = amt * Math.pow(10, decimals)
	var result2 = Math.round(result1)
	var result3 = result2 / Math.pow(10, decimals)

	return (result3)
}

function CalculateTax(income, show)
{
	// declare arrays for data from tax table
	var taxrate = new Array(11)
	var basictax = new Array(10)
	var incomelevel = new Array(10)
	var cnt, bracket
	
	taxrate[0] = 0.00; incomelevel[0] = 8012; basictax[0] = 0
	taxrate[1] = 0.16; incomelevel[1] = 11118; basictax[1] = 496.96
	taxrate[2] = 0.281; incomelevel[2] = 14193; basictax[2] = 1361.04
	taxrate[3] = 0.2205; incomelevel[3] = 33375; basictax[3] = 5590.67
	taxrate[4] = 0.2515; incomelevel[4] = 35000; basictax[4] = 5999.36
	taxrate[5] = 0.3115; incomelevel[5] = 58768; basictax[5] = 13403.09
	taxrate[6] = 0.3298; incomelevel[6] = 66752; basictax[6] = 16036.21
	taxrate[7] = 0.3539; incomelevel[7] = 69238; basictax[7] = 16916.01
	taxrate[8] = 0.3941; incomelevel[8] = 70000; basictax[8] = 17216.31
	taxrate[9] = 0.4341; incomelevel[9] = 113804; basictax[9] = 36231.63
	taxrate[10] = 0.4641;
	
	// reset counter
	cnt = 0
	bracket = 0

	if(show){
		// if income is higher than exempt limit then determine which income level they are at
		if(income > incomelevel[0]){
			// write the beginning bracket tax info	
			window.TaxBox.TaxTextBox.value = window.TaxBox.TaxTextBox.value +  "$0" + " - $" + incomelevel[0] + "\n"
			window.TaxBox.TaxTextBox.value = window.TaxBox.TaxTextBox.value +  "Tax Due:  Exempt" + "\n\n"

			// loop through all tax brackets and write income bracket & tax info
			for(cnt = 1; cnt < incomelevel.length; cnt++){
				// if income is higher then previous bracket
				if(income > incomelevel[cnt-1]){
					// if income is within the current bracket write info
					if(income <= incomelevel[cnt]){
						window.TaxBox.TaxTextBox.value = window.TaxBox.TaxTextBox.value +  "$" + (incomelevel[cnt-1]+1) + " - $" + income + "\n"
						window.TaxBox.TaxTextBox.value = window.TaxBox.TaxTextBox.value +  "Tax Due: $" + RoundDollar((income - incomelevel[cnt-1]) * taxrate[cnt], 2) + "\n\n"
					
						//  set bracket to the right bracket number
						bracket = cnt
					}  // end if
				
					// if income is higher then current bracket write basic tax info
					if(income > incomelevel[cnt]){
						window.TaxBox.TaxTextBox.value = window.TaxBox.TaxTextBox.value +  "$" + (incomelevel[cnt-1]+1) + " - $" + incomelevel[cnt] + "\n"
						window.TaxBox.TaxTextBox.value = window.TaxBox.TaxTextBox.value +  "Tax Due: $" + RoundDollar(basictax[cnt]-basictax[cnt-1], 2) + "\n\n"
					}  // end if
				}  // end if
			}  // end for
			
			// if income is higher than the highest bracket write that bracket info
			// if not return the current value.
			if(income > incomelevel[incomelevel.length-1]){
				window.TaxBox.TaxTextBox.value = window.TaxBox.TaxTextBox.value +  "$" + (incomelevel[incomelevel.length-1]+1) + " - $" + income + "\n"
				window.TaxBox.TaxTextBox.value = window.TaxBox.TaxTextBox.value +  "Tax Due: $" + RoundDollar((income - incomelevel[incomelevel.length-1]) * taxrate[taxrate.length-1], 2) + "\n\n"
				bracket = incomelevel.length-1
			}
				
		window.TaxBox.TaxTextBox.value = window.TaxBox.TaxTextBox.value + "\nTotal Tax Due: $" + RoundDollar(((income - incomelevel[bracket-1]) * taxrate[bracket]) + basictax[bracket-1], 2)
		}else{  // else if the income is tax exempt return 0 tax payable
			window.TaxBox.TaxTextBox.value = window.TaxBox.TaxTextBox.value +  "$0" + " - $" + income + "\n"
			window.TaxBox.TaxTextBox.value = window.TaxBox.TaxTextBox.value +  "Tax Due:  Exempt" + "\n\n"
			return (0)
		} // end else
	}else{	 // else if you don't want to show calculations
		for(cnt = 1; cnt < incomelevel.length; cnt++){
			// if income is higher then previous bracket
			if((income > incomelevel[cnt-1]) && (income <= incomelevel[cnt])){
				//  set bracket to the right bracket number
				bracket = cnt
			}  // end if
		}  // end for
		
		if(income > incomelevel[incomelevel.length-1]){ bracket = incomelevel.length-1}

		return (RoundDollar(((income - incomelevel[bracket-1]) * taxrate[bracket]) + basictax[bracket-1], 2))
	} // end else(show)
}  // end function
</script>
</head>

<body>
		This is to teach people to how to calculate<br>
		income tax:
		
		<form name="TaxBox" class="text8">
			Income: &nbsp;&nbsp;<input type="text" size="8" name="UserIncome" />
			<br>
			<input class="buttons" type="button" value="Calculate Tax" onClick="if(window.TaxBox.UserIncome.value > 0){ChangeClass('TaxTextBox', 'showtextbox'); CalculateTax(window.TaxBox.UserIncome.value, true)}else{window.TaxBox.TaxTextBox.value = 'Im sorry please enter a valid income.'}">
			<br>
			<br>
			<textarea name="TaxTextBox" cols="17" class="showtextbox" style="overflow:visible; " readonly>Your calculations will show here.</textarea>
		</form>
</body>
</html>
zincoxide is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 12-19-2004, 03:09 PM
Extreme Talker

Posts: 158
You are referencing the form incorrectly.
The forms array belongs to the document object.

For example you have

window.TaxBox.TaxTextBox.value

It should be

document.TaxBox.TaxTextBox.value;

If you wanted to use the full scope you could do

window.document.TaxBox.TaxTextBox.value;

but this is not required or practical.

HTH
ElectricSheep is offline
Reply With Quote
View Public Profile
 
Old 12-19-2004, 08:26 PM
Webmaster Talker

Posts: 554
Thank you, that got it functioning in all browsers however, now when it executes in Opera & FF. The textarea box doesn't expand like I want (as it does it IE).

I have noticed that the overflow/overflow:visible/overflow:hidden doesn't seem to have an effect in Opera & FF only in IE. Do you know how I could get it working???

thanks.
zincoxide is offline
Reply With Quote
View Public Profile
 
Old 12-20-2004, 02:36 PM
Extreme Talker

Posts: 158
Standards-wise overflow:visible is not intended for form tags such as <textarea>.
As far as I know Internet Explorer is the only browser that supports overflow on this element so that means IE is not following the standard - well there's a turn up! ;-)
ElectricSheep is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Code is not executing in Opera, Mozilla/FireFox or on a MAC.
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12000 seconds with 12 queries