So I'm doing this for a summer class and I have to get this carpet calculator to display the result in a "Perform a document.write to display the results on a new html page." (quote taken straight from assignment). It says to use document.write and I grasp the concept of document.write after using some tutorials on w3 but when I try to apply it to my project, it has no effect on my web page.
Below is my code:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<link rel="stylesheet" href="http://www.w3.org/StyleSheets/Core/Oldstyle" type="text/css" />
<head>
<title>Tutorial Project 10</title>
</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>
<script type="text/javascript">
function ComputeSquareFeet()
{
var SqFt = (carpet.length.value*carpet.width.value);
carpet.SqFtResult.value = SqFt+(SqFt*(carpet.overage.value / 100));
document.write(SqFtResult);
}
function ComputeSquareYards()
{
var SqYd = ((carpet.length.value/3)*(carpet.width.value/3));
carpet.SqYdResult.value = SqYd+(SqYd*(carpet.overage.value / 100));
document.write(SqYdResult);
}
</script>
</body>
</html>
The page works like this, the user enters data into 3 boxes, the button is pressed which calls the function and at the end of that function, it performs document.write. However, after doing a bunch of trial and error, I concluded that my formulas were working and the function was being called but the document.write wasn't for some reason.
Any ideas on what I'm doing wrong? Thank you!
Edit: I had a text box that displayed the result of the function just to make sure it was working but once I switched to document.write, nothing seemed to work