Question

In: Computer Science

Provide two text boxes for the user to enter in 2 values. Once the user clicks...

Provide two text boxes for the user to enter in 2 values. Once the user clicks off the second box, the
sum of the two numbers displayed as a header level 2.


here is what i have , and i cant find a way to display the sum of the numbers in each box in the header along with the other text.

<h1>Problem 6</h1>
<input type="text" id="txt1" onkeyup="sum();" />
<input type="text" id="txt2" onkeyup="sum();" />
<h2 id="txt3" result=""> The sum of the two numbers is=""</h2>
   <script>
   function sum() {
var txtFirstNumberValue = document.getElementById('txt1').value;
var txtSecondNumberValue = document.getElementById('txt2').value;
var result = parseInt(txtFirstNumberValue) + parseInt(txtSecondNumberValue);
if (!isNaN(result)) {
document.getElementById('txt3').value = result;
}
}
   </script>

Solutions

Expert Solution

HTML file :

<!DOCTYPE html>

<html lang="en">

<head>

    <title></title>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1">

</head>

<body>

    <h1>Problem 6</h1>

    <input type="text" id="txt1" />

    <input type="text" id="txt2" onblur="sum()" />

    <h2 id="txt3" result=""> The sum of the two numbers is =</h2>

    <script>

        //function sum()

        function sum() {

            //getting first number entered by user

            var txtFirstNumberValue = document.getElementById('txt1').value;

            //getting second number entered by user

            var txtSecondNumberValue = document.getElementById('txt2').value;

            //add numbers

            var result = parseInt(txtFirstNumberValue) + parseInt(txtSecondNumberValue);

            if (!isNaN(result)) {

                //display result

               document.getElementById('txt3').innerHTML = "The sum of the two numbers is ="+result;

            }

        }

    </script>

</body>

</html>

==============================================

Screen showing textboxes :

Screen showing result :


Related Solutions

Assignment 2: Create a form that collects 5 different pieces of data. Once the user clicks...
Assignment 2: Create a form that collects 5 different pieces of data. Once the user clicks the submit button, the processing PHP file displays the data that was entered thru the form, performs a calculation, and displays the result. To receive full credit, students need to implement the following: Create variables with valid names and assign values to them Use literals and concatenate strings Use $_POST Use echo statements to display data on a page Code string and numeric expressions...
Using python, allows a user to enter the values of two, 3x3 matrices and then select...
Using python, allows a user to enter the values of two, 3x3 matrices and then select from options including, addition, subtraction, matrix multiplication, and element by element multiplication. You should use numpy.matmul()for matrix multiplication(e.g. np.matmul(a, b)).The program should computer the appropriate results and return the results, the transpose of the results, the mean of the rows for the results, and the mean of the columns for the results.When entering data you should check that each value is numeric for the...
Write a C program that asks the user to enter double values (the values can be...
Write a C program that asks the user to enter double values (the values can be positive, zero, or negative). After entering the first double value, the program asks "Would you like to enter another value?", and if the user enters Y or y, the program continues to get additional values and stores these values into a double array (for up to 100 values — use a symbolic #define constant to specify the 100 size limit). The program will need...
ARDUINO Create a function that will ask the user to enter the values for each of...
ARDUINO Create a function that will ask the user to enter the values for each of the three colors (red, green and blue) between 0 and 255. The function should check that the user does not enter a number bigger than 255 or smaller than 0. If this happens, the function should keep asking for a valid number.
Write in C# please! Ask the user to enter all of their exam grades. Once they...
Write in C# please! Ask the user to enter all of their exam grades. Once they are done, calculate the minimum score, the maximum score and the average score for all of their scores. Perform this using at least 2 Loops (can be the same type of loop) and not any built in functions.
Write a Java program that prompts the user to enter a list of integer values and...
Write a Java program that prompts the user to enter a list of integer values and displays whether the list is sorted in increasing order or not. Here is a sample run. Note that the first number in the input indicates the number of the elements in the list. <Output> Enter list: 8 101516619111 The list is not sorted <End Output <Output> Enter list: 10 11344579 11 21 The list is already sorted <End Output Create a complete class for...
Use a sentinel while loop that repeatedly prompts the user to enter a number, once -1...
Use a sentinel while loop that repeatedly prompts the user to enter a number, once -1 is entered, stop prompting for numbers and display the maximum number entered by the user. I am struggling to have my program print the math function. Here is what I have so far: import java.util.*; public class MaxSentinel { public static void main(String[] args) {    Scanner input = new Scanner(System.in); System.out.println("Please enter a value. Press -1 to stop prompt."); int number = 0;...
JAVA Programming Implement the class DataProcess and prompt a user to enter 5 integer numbers. Once...
JAVA Programming Implement the class DataProcess and prompt a user to enter 5 integer numbers. Once The program should output the average, largest, and smallest of 5 numbers. You must implement the methods listed below in your program. static float getAverage(int[] data) {...} static int getLargest(int[] data) {...} static int getSmallest(int[] data) {...}
IN C++ Write a program that reads in int values from the user until they enter...
IN C++ Write a program that reads in int values from the user until they enter a negative number like -1. Once the user has finished entering numbers, print out the highest value they’ve entered, the lowest value they’ve entered, and the total number of numbers they’ve entered. The negative number they entered should not be taken as one of the values entered.
*Create a python function that uses a while list to allow a user to enter values...
*Create a python function that uses a while list to allow a user to enter values for sales and to add each value into a list in order to track all values entered. Set the gathering of values to stop when the value of zero is entered. Then take the created list and calculate the values within the list to return the total for all the values. Next, take the previously created list and display all the values from smallest...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT