babylikesburgh
08-06-2008, 03:23 PM
I've gotten to this point with my code. It should input sales, calculate commission and total pay and add 1 to each array (which represents the ranges of income) to finally show the total number of each employee earning sales in each range. Yet, nada is happening. Any suggestions?
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Calling a function</title>
<script type = "text/javascript">
<!--
var empSales
var empSalesInt
var basePay = 200
var total = new Array(9)
start();
function start()
{
for ( var i = 0; i < a.length; ++i )
total[i]=0
}
function addToArray()
{
var x;
var sales = document.getElementById( "inputVal" ).value;
var salary;
salary = 200 + parseInt(sales.newEntry.value ) * 0.09;
x = Math.floor( salary / 100 );
if( salary < 0 )
return
else if( x > 9 )
{
x = 10
++total[x-2]
}
if( x > 8 )
{
x = 9
++total[x-2]
}
else if( x > 7 )
{
x = 8
++total[x-2]
}
if( x > 6 )
{
x = 7
++total[x-2]
}
else if( x > 5 )
{
x = 6
++total[x-2]
}
if( x > 4 )
{
x = 5
++total[x-2]
}
else if( x > 3 )
{
x = 4
++total[x-2]
}
if( x > 2 )
{
x = 3
++total[x-2]
}
else if( x > 1 )
{
x = 2
++total[x-2]
}
outputArray();
}
function outputArray()
{
var sales = document.getElementById( "inputVal" );
document.write( "<h3>The total sales by amount ranges are: " +
"$200-299: " + total[0] +
"$300-399: " + total[1] +
"$400-499: " + total[2] +
"$500-599: " + total[3] +
"$600-699: " + total[4] +
"$700-799: " + total[5] +
"$800-899: " + total[6] +
"$900-999: " + total[7] +
"$1000 and over: " + total[8] + "</h3>" );
}
//-->
</script>
<body>
<form action = "">
<p>Enter sales for current employee for this week:<br />
<input id = "inputVal" type = "text" />
<input type = "button" value = "Enter"
onclick = "addToArray()" /><br /></p>
</form>
</body>
</html>
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Calling a function</title>
<script type = "text/javascript">
<!--
var empSales
var empSalesInt
var basePay = 200
var total = new Array(9)
start();
function start()
{
for ( var i = 0; i < a.length; ++i )
total[i]=0
}
function addToArray()
{
var x;
var sales = document.getElementById( "inputVal" ).value;
var salary;
salary = 200 + parseInt(sales.newEntry.value ) * 0.09;
x = Math.floor( salary / 100 );
if( salary < 0 )
return
else if( x > 9 )
{
x = 10
++total[x-2]
}
if( x > 8 )
{
x = 9
++total[x-2]
}
else if( x > 7 )
{
x = 8
++total[x-2]
}
if( x > 6 )
{
x = 7
++total[x-2]
}
else if( x > 5 )
{
x = 6
++total[x-2]
}
if( x > 4 )
{
x = 5
++total[x-2]
}
else if( x > 3 )
{
x = 4
++total[x-2]
}
if( x > 2 )
{
x = 3
++total[x-2]
}
else if( x > 1 )
{
x = 2
++total[x-2]
}
outputArray();
}
function outputArray()
{
var sales = document.getElementById( "inputVal" );
document.write( "<h3>The total sales by amount ranges are: " +
"$200-299: " + total[0] +
"$300-399: " + total[1] +
"$400-499: " + total[2] +
"$500-599: " + total[3] +
"$600-699: " + total[4] +
"$700-799: " + total[5] +
"$800-899: " + total[6] +
"$900-999: " + total[7] +
"$1000 and over: " + total[8] + "</h3>" );
}
//-->
</script>
<body>
<form action = "">
<p>Enter sales for current employee for this week:<br />
<input id = "inputVal" type = "text" />
<input type = "button" value = "Enter"
onclick = "addToArray()" /><br /></p>
</form>
</body>
</html>