OneCompiler

Area and Circumference of rectangle program with HTML, javascript & jQuery

1421

Demo

<iframe height='265' scrolling='no' title='dzRqeB' src='//codepen.io/fastfoodcoding/embed/dzRqeB/?height=265&theme-id=light&default-tab=result&embed-version=2' frameborder='no' allowtransparency='true' allowfullscreen='true' style='width: 100%;'>See the Pen <a href='https://codepen.io/fastfoodcoding/pen/dzRqeB/'>dzRqeB</a> by fastfoodcoding (<a href='https://codepen.io/fastfoodcoding'>@fastfoodcoding</a>) on <a href='https://codepen.io'>CodePen</a>. </iframe>

Code

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
	//Area
       $("#mul").click(function(){
		var a = $("#width").val();
		var b = $("#height").val();
		 $("#result").val ((+a) * (+b));
	});
	
   //Circumference 
   $("#add").click(function(){
   var a = $("#width").val();
   var b  = $("#height").val();
   $("#result").val (2 *(+a) + 2 * (+b));
   });
});
</script>
</head>
<body>
<div>
Enter width value:
<input type = "text" id = "width"><br><br>
Enter height value:
<input type = "text" id = "height"><br><br>
Result:
<input type = "text" id = "result"><br><br><br>
<button type = "button" id = "mul"> Area</button>
<button type = "button" id = "add"> Circumference</button>
</div>
</body>
</html>