<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>
yea my code looked like a 1st grade version of yours
thanks a ton for your help. i'm sure i'll be making a new thread since my next assignment is due on wednesday lol
You're welcome, but make sure you are a lot further along before coming to this forum. This should be the last resort, not the first. Someone on a programming forum I used to visit was notorious for a curt "Do your own homework," message when a student posted a question without showing any indication any work had been put in on it.
yea i always try my best to learn from the books, but it's never enough. people on forums always seem to help me get my mind going in the right direction for learning how to do things myself. plus i was kinda just thrown into javascript without any kind of lesson so having someone with experience guide me along the right way is a huge help. my mind was stuck on VB so my functions weren't working until i was able to compare both of our scripts and see what i was missing (which was quite a bit lol). thanks again buddy
Hello,
I am working on the same and stuck with the exactly same problem with document.write. Can you please help me with the same?
(I also have same HTML code you have posted here)
Thanks a lot
-Ashjay
Bookmarks