Web Analytics Made Easy -
StatCounter Need help with square feet and square yards in HTML (javascript) - CodingForum

Announcement

Collapse
No announcement yet.

Need help with square feet and square yards in HTML (javascript)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help with square feet and square yards in HTML (javascript)

    So I trying to make a calculator and I already have the calculator made but I need to make it so the square yards and square feet do their functions. The calucation for square feet should be 1*w + (1*w*o)*.01. The calculation for square yards should be: (1*w + (1*w*o)*.01)/9

    The variables should be :

    var l = carpet.length.value
    var w = carpet.width.value
    var o = carpet.overage.value



    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>Project 3</title>
    <!--
    Author: 
    Date: October 6th, 2016
    -->
    
    
    function ComputeSquareFeet ()
    {
    
    
    
    
    }
    
    function ComputeSquareYards ()
    {
    
    
    
    
    }
    
    
    </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>

  • #2
    Need help with square feet and square yards in HTML (javascript)

    hope this points you in the right direction. Eventually you may want to include checks for invalid numbers or NaN.

    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>Project 3</title>
    <!--
    Author: 
    Date: October 6th, 2016
    -->
    
    <script>
    function ComputeSquareFeet (){
    var l = carpet.length.value;
    var w = carpet.width.value;
    var o = carpet.overage.value;
    var a = l * w;
    var b = a * o;
    var c = b * 0.01;
    var answer = a + c;
    alert(answer);
    }
    
    function ComputeSquareYards (){
    var l = carpet.length.value;
    var w = carpet.width.value;
    var o = carpet.overage.value;
    var a = l * w;
    var b = a * o;
    var c = b * 0.01;
    var answer = (a + c)/9;
    alert(answer);
    }
    
    function reset (){
    carpet.length.value = '';
    carpet.width.value = '';
    carpet.overage.value = '';
    }
    </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" onclick = "reset();"; />
    
    </form>
    
    </body>
    </html>
    Sent from my iPhone using Tapatalk
    Last edited by charlie666; Oct 8, 2016, 11:26 AM.

    Comment


    • #3
      I don't know how that last ; got there but feel free to delete it lol.


      Sent from my iPhone using Tapatalk

      Comment

      Working...
      X