In this article, I will show you how to add numbers in html using onkeyup() event in JavaScript. Here, when the user enters the values in the first two textbox values without pressing any buttons it sums the values automatically in the third textbox.
SCRIPT CODE:
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
function sum() {
var txtFirstNo = document.getElementById('txtFirstNo').value;
var txtSecondNo = document.getElementById('txtSecondNo').value;
var result = parseInt(txtFirstNo) + parseInt(txtSecondNo);
if (!isNaN(result)) {
document.getElementById('txtResult').value = result;
}
}
</script>
HTML CODE:
<div style="border:1px solid gray;width: 450px; height:300px">
<h2>Add two textbox values without pressing anybuttons</h2>
<input type="text" id="txtFirstNo" placeholder="pleaseenterFirst Number" onkeyup="sum()" />
<input type="text" id="txtSecondNo" placeholder="pleaseenterSecond Number" onkeyup="sum()" />
<br />
<div style="padding-top:10px">
Result:
<input type="text" id="txtResult" />
</div></div>
Output:
Below video will demonstrate how to add two textbox values and display the sum in a third using onkeyup() event in JavaScript. Here, when the user enters the values in the first two textbox values without pressing any buttons it sums the values automatically in the third textbox.
Post your comments / questions
Recent Article
- How to fix HAXM is not installed |in Android Studio
- How to fix CMOS Checksum Error in Computer or Laptop | SOLVED
- Reactivating windows after a Hardware change on PC or Laptop
- FIXED: Windows reported that the hardware of your device has changed. Error code :0xc004F211
- "redirect" is not defined pylance("reportUndefinedVariable)
- This action cannot be completed because the file is open in SQL Server(SQLEXPRESS) - FIXED
- Unicode error 'unicodeescape' codec can't decode bytes in position 2-3: truncated UXXXXXXXX escape
- Could not find the 'angular-devkit/build-angular:dev-server' builder's node package | Angular Error
Related Article