# Function for Computing Square Feet and Yard

Show 40 post(s) from this thread on one page
Page 2 of 2 First 12
• 12-01-2012, 11:16 PM
wbport
Here's a clue. The answer is in post #4 in the middle paragraph.
• 12-01-2012, 11:58 PM
guero311
Quote:

Originally Posted by wbport
Here's a clue. The answer is in post #4 in the middle paragraph.

well...that's easier than i expected lol
• 12-02-2012, 10:27 AM
007Julien
Read this w3school.com «Basic examples» page and particularly the first links and Examples explained
• 12-02-2012, 11:22 PM
wbport
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>```
• 12-03-2012, 05:13 PM
guero311
yea my code looked like a 1st grade version of yours :p
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
• 12-03-2012, 05:59 PM
wbport
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.
• 12-03-2012, 11:00 PM
guero311
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
• 12-06-2012, 10:18 PM
ashjay
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
Show 40 post(s) from this thread on one page
Page 2 of 2 First 12

## X vBulletin 4.2.2 Debug Information

• Page Generation 0.11753 seconds
• Memory Usage 2,373KB
• Queries Executed 11 (?)
Template Usage (24):
• (1)bbcode_code_printable
• (1)bbcode_quote_printable
• (1)footer
• (1)gobutton
• (1)navbar_moderation
• (1)navbar_noticebit
• (2)option
• (1)pagenav
• (1)pagenav_curpage
• (1)spacer_close
• (1)spacer_open

Phrase Groups Available (3):
• global
• postbit
Included Files (19):
• ./global.php
• ./includes/class_bootstrap.php
• ./includes/init.php
• ./includes/class_core.php
• ./includes/config.php
• ./includes/functions.php
• ./includes/class_friendly_url.php
• ./includes/class_hook.php
• ./includes/class_bootstrap_framework.php
• ./vb/vb.php
• ./vb/phrase.php
• ./includes/functions_calendar.php
• ./includes/class_bbcode_alt.php
• ./includes/class_bbcode.php
• ./includes/functions_bigthree.php
• ./includes/functions_notice.php

Hooks Called (43):
• init_startup
• init_startup_session_setup_start
• database_pre_fetch_array
• database_post_fetch_array
• init_startup_session_setup_complete
• global_bootstrap_init_start
• global_bootstrap_init_complete
• cache_permissions
• fetch_foruminfo
• global_state_check
• global_bootstrap_complete
• global_start
• style_fetch
• global_setup_complete
• friendlyurl_resolve_class
• friendlyurl_clean_fragment
• friendlyurl_geturl
• pagenav_page
• cache_templates
• cache_templates_process
• template_register_var
• template_render_output
• fetch_template_start
• fetch_template_complete
• parse_templates