Was this pretty much close to your solution?
Code:
<html><head><title>Carpet Calculator</title>
<script language="JavaScript">
function verifyOverage() {
var iOverage, fOverage;
if ((iOverage = parseInt(document.carpet.overage.value)) != (fOverage = parseFloat(document.carpet.overage.value)))
return -1;
else
if (iOverage >= 0 && iOverage <= 20)
return iOverage;
else
return -1;
}
function calculate(parm) {
var answer;
var overage = verifyOverage()
if (overage == -1)
alert("Overage must be an integer percent in the range 0-20");
else {
answer = (document.carpet.length.value * document.carpet.width.value * (1 + overage / 100))/parm;
var wHeight = 80
var wWidth = 475
var AvailWidth = window.screen.availWidth
var AvailHeight = window.screen.availHeight
var hOffset = parseInt(AvailWidth/2) - parseInt(wWidth/2)
var vOffset = parseInt(AvailHeight/2) - parseInt(wHeight/2)
var wOption = "resizable,status,scrollbars,width=" + wWidth + ",height=" + wHeight +
",left=" + hOffset+ ",top=" +vOffset
var w = window.open("","gentable",wOption);
var html = "<html><head><title>Carpet Answer</title></head><body>You need " +answer+ " square "
html += (parm == 9)? "yards":"feet";
html += ".</body></html>";
w.document.write(html);
w.document.close(); }
}
function ComputeSquareFeet() {
calculate(1); }
function ComputeSquareYards() {
calculate(9); }
</script>
</head>
<body>
<h1>Carpet Calculator</h1>
<form name = "carpet" action=" ">
</br>Enter the length of your room in feet</br><input name = "length" type = "text" />
</br>Enter the width of your room in feet</br><input name = "width" type = "text" />
</br>Typically an allowance is made for room irregularities and unavoidable waste.
</br>Enter the percent overage as an integer in the interval [0, 20]</br><input name = "overage" type = "text" />
</br></br><input name = "SqFt" type = "button" value = "Compute Square Feet " onclick = "ComputeSquareFeet()" />
</br></br><input name = "SqYd" type = "button" value = "Compute Square Yards" onclick = "ComputeSquareYards()" />
</br></br><input type = "reset" value = "Clear" />
</form>
</body>
</html>
Bookmarks