Advertisements
Advertisements
प्रश्न
Write event driven JavaScript program for the following.
Display Addition, subtraction, multiplication, division and remainder of two numbers, which were accepted from user.
थोडक्यात उत्तर
उत्तर
Coding:
<!DOCTYPE html>
<html>
<body>
<form>
<label>First number: <input type="number" name="n1" /></label><br />
<label>Second number: <input type="number" name="n2" /></label><br />
<input type="submit" value="Submit" />
<div id="output"></div>
</form>
</body>
<script type="text/javascript">
var form = document.querySelector('form');
form.addEventListener('submit', function (e) {
e.preventDefault();
var formData = new FormData(form);
var a = parseInt(formData.get('n1'));
var b = parseInt(formData.get('n2'));
var res;
var out = '';
res = a + b;
out += "<br><br>Addition is: " + res;
res = a - b;
out += "<br><br>Subtraction is: " + res;
res = a * b;
out += "<br><br>Multiplication is: " + res;
res = a / b;
out += "<br><br>Division is: " + res;
res = a % b;
out += "<br><br>Remainder is: " + res;
document.querySelector("#output").innerHTML = out;
});
</script>
</html>
shaalaa.com
DOM (Document Object Model)
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?