Create a HTML Document with JavaScript code that has three Textboxes and a button.
The details should be accepted using textboxes are principal, rate of interest, and
duration in years. When user clicks the OK Button a message box appears showing the
simple interest of principal amount.
<html>
<head>
<title>Simple Interest Calculator</title>
</head>
<body>
<p>Principal: <input type="text" id="principal" /></p>
<p>Rate of Interest: <input type="text" id="rate" /></p>
<p>Duration (years): <input type="text" id="duration" /></p>
<p><button onclick="calculateInterest()">OK</button></p>
<script>
function calculateInterest() {
var principal = document.getElementById("principal").value;
var rate = document.getElementById("rate").value;
var duration = document.getElementById("duration").value;
var interest = (principal * rate * duration) / 100;
alert("The simple interest is: " + interest);
}
</script>
</body>
</html>
Output:
Principal:
Rate of Interest:
Duration (years):
You must log in to post a comment.