I have written the following JavaScript, but none of the code seems to work at all. I am at a loss as to what the errors are, Firefox's debugger did not help, and I don't know what to do. Can anyone help?
Code:
<html>
<head>
<title>Solar Energy Products</title>
<script language="Javascript">
function main (txtPamphletMin,txtPamphletMax,optQuality,selIncrement,txtResults)
{
var pamphletMin,pamphletMax,quality,increment;
var amount = 100;
var errorMsg = "";
var results = "";
pamphletMin = parseInt(pamphletMin.value); //Make sure that the minimum number of pamphlets required is entered
if (pamphletMin < 100)
{
errorMsg = "Number of pamphlets must be above 100";
}
else
{
pamphletMin = txtPamphletMin.value; //get the number of pamphlets from the text box
}
if(errorMsg == "") //still no errors
{
quality = getQuality(optQuality);
if(quality == "") //this means that no processor was selected
{
errorMsg = "Quality type must be selected";
}
}
if(errorMsg == "") //still no errors
{
increment = getIncrement(selIncrement);
if(increment < 0)
{
errorMsg = "Increment amount must be selected";
}
}
if(errorMsg == "")
{
txtResults.value = generatePriceTable (pamphletMin,pamphletMax,quality,increment)
}
else
{
txtResults.value = errorMsg;
}
}function validatePamphletMin(pamphletMin)
{
var errorMsg = "";
if(pamphletMin == "")
{
errorMsg = "Please enter Minimum amount of pamphlets";
}
else
{
}
function getQuality(optQuality)
{
var selNdx = -1, selValue, quality;
for(var i = 0; i < optQuality.length; i++)
{
if(optQuality[i].checked == true)
{
selNdx = i; // grab index
break; // bail out of loop
}
}
if(selNdx == -1)
{
quality = "";
}
else
{
quality = optQuality[selNdx].value;
}
return quality;
}
function getPamphletIncrement(selPamphlet)
{
var pamphletIncrement, selValue;
var selNdx = selIncrement.selectedIndex;
if (selNdx == -1) //this means nothing has been selected
{
pamphletIncrement = -1;
}
else
{
selValue = selPamphletIncrement.options[selNdx].value;
pamphletIncrement = parseInt(selValue);
}
return pamhpletIncrement;
}
function generatePriceTable (pamphletMin,pamphletMax,quality,increment)
{
var count, unitPrice, results, discount, discAmt, totalPrice, finalPrice;
results = "Hello " + name +
"\nYou want to order the following :- \n" +
"Quality of Pamphlets : " + quaility + "\n" +
" Amount of pamphlets Price\n";
unitPrice = calcPrice(quality, increment);
count = 1;
while (count <= 20)
{
if (count < 6)
{
discount = 0;
}
else
{
if (count < 11)
{
discount = 5;
}
else
{
if (count < 16)
{
discount = 10;
}
else
{
discount = 15;
}
}
}
totalPrice = count * unitPrice;
finalPrice = totalPrice - (totalPrice * discount / 100);
results = results + " " + fmtAmt(count,0,2) + " " + fmtAmt(finalPrice,2,8) + "\n";
count = count + 1;
}
return results;
}
function calcPrice(quality, increment)
{
var price = 0;
if(pquality == "A")
{
price = 600;
}
else
{
price = 700;
}
price = price + quality * 0.225
return price;
}
function fmtAmt(amt, numDp, width)
{
/* Returns string version of amt rounded to numDp decimal places, with
numDp digits after decimal, in a field width wide, right aligned */
var strAmt;
if(numDp > 0)
{
strAmt = "" + Math.round(amt * Math.pow(10, numDp)) / Math.pow(10, numDp);
}
else
{
strAmt = "" + Math.round(amt);
}
if(numDp > 0)
{
if(strAmt.indexOf(".") == -1) strAmt += ".";
while(strAmt.length - strAmt.indexOf(".") < numDp + 1)
strAmt += "0";
}
while(strAmt.length < width)
{
strAmt = " " + strAmt;
}
return strAmt;
}
</script>
</head>
<body onLoad="">
<h1>Advertising Cost Calculation</h1>
<form name="frmBuild">
<b>Minimum number of Pamphlets required </b><input type="Text" name="txtName" value="100">
<b>Maximum Number of Pamphlets required</b> <input type="Text" name="txtEmail" value="600">
<br><b>Quality</b>
<input type="Radio" name="optType" value="A" >A
<input type="Radio" name="optType" value="B">B
<input type="Radio" name="optType" value="C">C
<input type="Radio" name="optType" value="D">D
<b>Increment in Number of Pamphlets required: </b>
<select name="selHardDrive" size="1" >
<option value="100" >100 </option>
<option value="200">200</option>
<option value="500">500</option>
</select>
<p><input type="Button" value="Calculate Advertising Costs" onClick="main(txtName,txtEmail,optType,selHardDrive,txtResults);">
<p><textarea name="txtResults" rows="27" cols="70"></textarea>
</form>
</body>
</html>