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...
write a PHP program that initially has button called START QUIZ, once the user clicks on...
write a PHP program that initially has button called START QUIZ, once the user clicks on it, it should randomly select 5 questions from the array and display them in proper quiz format. the user should see a message as follows: START TIME"9:07 AM DATE: 8 OCT 2020 YOU HAVE ONLY 5 MIN TO SUMBIT YOUR QUIZ the user should submit the quiz within 5 minutes, so the quiz score should be shown out of 5. in addition it should...
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...
Use a while(true) loop to ask the user the following 2 values “Enter a rate r...
Use a while(true) loop to ask the user the following 2 values “Enter a rate r =” “Enter a nonnegative integer (enter negative integer to quit):” If the user enters a negative int for n, the while loop is broken via the brake statement. Otherwise, in the remaining part of the while loop, use a for loop to compute the partial sum for the geometric series, namely 1 + r + rˆ2 + rˆ3 + . . . +rˆn. Use...
Use a while(true) loop to ask the user the following 2 values “Enter a value x...
Use a while(true) loop to ask the user the following 2 values “Enter a value x “ “Enter a nonnegative integer n (enter negative integer to quit): “ If the user enters a negative int for n, the while loop is broken via the brake statement. Otherwise, in the remaining part of the while loop, use a for loop to compute the partial sum for the Riemann zeta series for the geometric series, namely 1 + 2ˆ-x + 3ˆ-x +...
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.
Use c programing. Declare a new employee struct. Prompt the user to enter values for two-member...
Use c programing. Declare a new employee struct. Prompt the user to enter values for two-member data of the struct. Store struct data in employee struct. Use the calculate(raise_function) to increase employee salary and store the result in employee structure. Use print_ structure to print employee structure.
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;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT