Addition Of Four Numbers Using JavaScript
Submitted by alpha_luna on Monday, April 11, 2016 - 12:36.
Good Day!!!
In this tutorial, we are going to learn a simple program and this is called Addition Of Four Numbers Using JavaScript. Which have HTML Form Tag to have the sum of four numbers. We have four text box to input the number to be added, one for sum button, and one for the reset button to clear the input number that the user has a new value of the number to be added. And all field is required. JavaScript Script This is the script to add the four values in a text box.- <script type="text/javascript">
- function four_numbers() {
- var first_number = document.getElementById("box_number_1").value;
- var second_number = document.getElementById("box_number_2").value;
- var third_number = document.getElementById("box_number_3").value;
- var fourth_number = document.getElementById("box_number_4").value;
- var result =parseInt(first_number)+parseInt(second_number)
- +parseInt(third_number)+parseInt(fourth_number);
- var box_number_5 = document.getElementById('box_number_5');
- box_number_5.value=result;
- }
- function clear_box() {
- document.getElementById("box_number_1").value="";
- document.getElementById("box_number_2").value="";
- document.getElementById("box_number_3").value="";
- document.getElementById("box_number_4").value="";
- }
- </script>
- <center>
- <input type="number" style="width:100px; font-size:18px; text-align:center;" autofocus="autofocus" step="1" min="0" name="box_number_1" id="box_number_1" size="3"/>
- <input type="number" style="width:100px; font-size:18px; text-align:center;" step="1" min="0" name="box_number_2" id="box_number_2" size="3"/>
- <input type="number" style="width:100px; font-size:18px; text-align:center;" step="1" min="0" name="box_number_3" id="box_number_3" size="3"/>
- <input type="number" style="width:100px; font-size:18px; margin-right:10px; text-align:center;" step="1" min="0" name="box_number_4" id="box_number_4" size="3"/>
- <input type="submit" name="button_all" id="button_all1" style="font-size:18px; color:red; background:azure;" onclick="four_numbers()" value=" = " title="Click here to find the sum of four values" />
- <input type="text" style="width:100px; text-align:center; font-size:18px;" name="box_number_5" id="box_number_5" size="10" readonly="true"/>
- <input type="submit" name="button_all" id="button_all1" style="font-size:18px; color:red; background:azure;" onclick="clear_box()" value="Reset" />
- </center>
Add new comment
- 1353 views