Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
JavaScript
<html>
<head>
  <title>CALUCLATING AREA AND PERIMETER</title>
<center><h1>CALUCLATOR FOR AREA & PERIMETER</h1></center>

  <style>
  
  </style>

  <script language="JavaScript">

    var x = new Array();
    var y = new Array();
    var vertices;
    var digits;
    var area;
    var perimeter;
    var r;
    var carea;
    var cperi;
    
    function readUserData()
    {
        
        vertices = parseInt( document.getElementById("VERTICES").value );
        if( (vertices < 2) || (vertices > 10 ) ) {
            alert( "Vertices must be >= 2 and <= 10" );
            return;
        }

       

        
       
        for( k = 0; k < vertices; k++ ) {
            x[k] = parseInt( document.getElementById("X"+k).value );
            y[k] = parseInt( document.getElementById("Y"+k).value );
        }
        
        x[vertices] = x[0];
        y[vertices] = y[0];
    }

    function calculateArea()
    {
        
        area = 0.0;
        for( k = 0; k < vertices; k++ ) {
            xDiff = x[k+1] - x[k];
            yDiff = y[k+1] - y[k];
            area = area + x[k] * yDiff - y[k] * xDiff;
        }
        area = 0.5 * Math.abs(area);
    }

    function calculatePerimeter()
    {
        

        perimeter = 0.0 
        for( k = 0; k < vertices-1; k++ ) {
            xDiff = x[k+1] - x[k];
            yDiff = y[k+1] - y[k];
            perimeter = perimeter + 
                        Math.pow( xDiff*xDiff + 
                        yDiff*yDiff, 0.5 );
        }
    }
function cir()
 {
 r= parseInt(document.getElementById("Y"+10).value);
 carea=3.1429*(r*r);
 cperi=6.2858*r;
alert(" circle area is "+carea);
alert(" circle perimeter is"+cperi);
}

    

    function handleCalculate()
    {
        readUserData();
        calculateArea();
        calculatePerimeter(); 
    
        alert("area is  "+area);
        alert("PERIMETER IS  "+perimeter);

    }

   
  </script>
</head>

<body>
<div align="center">
<div class="content">
<form>
<table border="2" cellspacing="0">
         cellpadding="2" style="border-collapse: collapse">

<tr>
<td colspan="2">Number of Vertices 
<input type="text" id="VERTICES" 
          size="5" value="0"></td>

</tr>
<tr>
<td align="center">Vertex</td>
<td colspan="2" align="left">X Value</td>
<td align="left">Y Value</td>
</tr>
<tr>
<td align="center">1</td>
<td colspan="2"><input type="text" 
               id="X0" size="20"></td>
<td><input type="text" id="Y0" size="20"></td>
</tr>
<tr>
<td align="center">2</td>
<td colspan="2"><input type="text" 
             id="X1" size="20"></td>
<td><input type="text" id="Y1" size="20"></td>
</tr>
<tr>
<td align="center">3</td>
<td colspan="2"><input type="text" 
             id="X2" size="20"></td>
<td><input type="text" id="Y2" size="20"></td>
</tr>
<tr>
<td align="center">4</td>
<td colspan="2"><input type="text" 
            id="X3" size="20"></td>
<td><input type="text" id="Y3" size="20"></td>
</tr>
<tr>
<td align="center">5</td>
<td colspan="2"><input type="text" 
           id="X4" size="20"></td>
<td><input type="text" id="Y4" size="20"></td>
</tr>
<tr>
<td align="center">6</td>
<td colspan="2"><input type="text" 
          id="X5" size="20"></td>
<td><input type="text" id="Y5" size="20"></td>
</tr>
<tr>
<td align="center">7</td>
<td colspan="2"><input type="text" 
         id="X6" size="20"></td>
<td><input type="text" id="Y6" size="20"></td>
</tr>
<tr>
<td align="center">8</td>
<td colspan="2"><input type="text" 
         id="X7" size="20"></td>
<td><input type="text" id="Y7" size="20"></td>
</tr>
<tr>
<td align="center">9</td>
<td colspan="2"><input type="text" 
         id="X8" size="20"></td>
<td><input type="text" id="Y8" size="20"></td>
</tr>
<tr>
<td align="center">10</td>
<td colspan="2"><input type="text" 
         id="X9" size="20"></td>
<td><input type="text" id="Y9" size="20"></td>
</tr>

<tr>
<td align="center"><input type="button" 
    value="Calculate"  önClick="handleCalculate()"></td>

<td align="center">
<input type="reset" value="Reset"></td>
</tr>
<tr><td>for circle:</td></tr>
<tr><td>ENTER radius <input type="text" id="Y10" size="20"></td></tr>
<tr><td><input type="submit" value="circleCaluclator"  önSubmit="cir()"></td></tr>

</form>
</table></div>
</div>
</body>
</html>
Posted
Updated 8-Sep-11 1:18am
v3
Comments
Suresh Suthar 8-Sep-11 7:20am    
Just code dump. What is the error? And where is the cir() function you are calling önSubmit="cir()".
Legor 8-Sep-11 7:23am    
Do you really think the people here are code monkeys you could just throw a pile of code at and they start looking for any error without having a clue (provided by you) about whats going on there, what its supposed to do and what isnt working?
LittleYellowBird 8-Sep-11 7:23am    
I think you need to explain what the error is. Use the 'Improve question' option at the bottom of your question to provide more details.

1 solution

replace onSubmit() with onClick()
and now check ur answer
 
Share this answer
 
Comments
Suresh Suthar 8-Sep-11 7:37am    
What is this? You are asking question and simply posting answer. You 420. (Thats you total reputation point right now)
Legor 8-Sep-11 8:32am    
Use the "Improve Question" button to edit your question above and dont wirte comments to whomever as answers..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900