www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23

Thread: Function for Computing Square Feet and Yard

  1. #16
    Join Date
    Sep 2008
    Location
    Jackson MS
    Posts
    374
    Here's a clue. The answer is in post #4 in the middle paragraph.

  2. #17
    Join Date
    Nov 2012
    Posts
    16
    Quote Originally Posted by wbport View Post
    Here's a clue. The answer is in post #4 in the middle paragraph.
    well...that's easier than i expected lol

  3. #18
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,270
    Read this w3school.com «Basic examples» page and particularly the first links and Examples explained

  4. #19
    Join Date
    Sep 2008
    Location
    Jackson MS
    Posts
    374
    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>

  5. #20
    Join Date
    Nov 2012
    Posts
    16
    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

  6. #21
    Join Date
    Sep 2008
    Location
    Jackson MS
    Posts
    374
    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.

  7. #22
    Join Date
    Nov 2012
    Posts
    16
    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

  8. #23
    Join Date
    Dec 2012
    Posts
    1
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles