logo image

Square area and circumference program with HTML, javascript & jQuery

187


Demo

Code

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