Question

In: Computer Science

Please create an Event-Based JavaScript Program of your choice. Please write new code for this project...

Please create an Event-Based JavaScript Program of your choice. Please write new code for this project (starting from scratch). Thank you!!

Solutions

Expert Solution

Program:

<html>
<head>
<title>an Event-Based JavaScript Program</title>

<script language="javascript">
function Addition(frm)
{
var num1,num2,ans;
//first textbox value is assigned to num1
num1=eval(frm.txtNumber1.value);
//second textbox value is assigned to num2
num2=eval(frm.txtNumber2.value);
ans=num1+num2;
//result of addition is returned to button where the onclick event is occured
return ans;
}

function Subtraction(frm)
{
var num1,num2,ans;
//first textbox value is assigned to num1
num1=eval(frm.txtNumber1.value);
//second textbox value is assigned to num2
num2=eval(frm.txtNumber2.value);
ans=num1-num2;
//result of Subtraction is returned to button where the onclick event is occured
return ans;
}

function Multiplication(frm)
{
var num1,num2,ans;
//first textbox value is assigned to num1
num1=eval(frm.txtNumber1.value);
//second textbox value is assigned to num2
num2=eval(frm.txtNumber2.value);
ans=num1*num2;
//result of multiplication is returned to button where the onclick event is occured
return ans;
}
function Division(frm)
{
var num1,num2,ans;
//first textbox value is assigned to num1
num1=eval(frm.txtNumber1.value);
//second textbox value is assigned to num2
num2=eval(frm.txtNumber2.value);
ans=parseFloat(num1/num2);
//result of division is returned to button where the onclick event is occured
return ans;
}
</script>
</head>
<body>
<form name="frm">
Number 1: <input type="text" name="txtNumber1"><br><br>
Number 2: <input type="text" name="txtNumber2"><br><br>
<input type="button" value="Addition" onclick="document.getElementById('result').innerHTML='Addition is '+Addition(frm)">
<input type="button" value="Subtraction" onclick="document.getElementById('result').innerHTML='Subtraction is '+Subtraction(frm)">
<input type="button" value="Multiplication" onclick="document.getElementById('result').innerHTML='Multiplication is '+Multiplication(frm)">
<input type="button" value="Division" onclick="document.getElementById('result').innerHTML='Division is '+Division(frm)">

</form>
<h1 id="result"></h1>
</body>
</html>

Output:


Related Solutions

Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to...
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to display the current day and time. b) Write a JavaScript program to print the contents of the current window.   c) Write a JavaScript program where the program takes a random integer between 1 to 10 d) Write a JavaScript program to calculate multiplication and division of two numbers (input from the user). e)Write a JavaScript program to create a new string from a given...
use VISUAL STUDIO CODE to write this javascript program Exercise 1 (a) Create a HTML file...
use VISUAL STUDIO CODE to write this javascript program Exercise 1 (a) Create a HTML file that uses createElement and appendChild to dynamically insert three paragraphs when a button is clicked. (b) Create a HTML file that includes JavaScript that is similar to: let recs = [“my item …1”,”my item…2”, …] i.e. an array that contains several CSV item records. When the user clicks a button, each array element will be rendered as a list element. Use a HTML list....
"Write in swift code only please, Create a SwiftUI project named DogBreeds based on the Contacts...
"Write in swift code only please, Create a SwiftUI project named DogBreeds based on the Contacts app. The app should be named DogBreeds. The app will display 10 dog images and names in a list"
WRITE CODE IN JAVA it is now your turn to create a program of your choosing....
WRITE CODE IN JAVA it is now your turn to create a program of your choosing. If you are not sure where to begin, think of a task that you repeat often in your major that would benefit from a program. For example, chemistry unit conversions, finding the area for geometric shapes, etc. You can also create an interactive story that changes based on the user input/decisions. The possibilities are endless. The program must include instructions for the user. Be...
write a C++ program to CREATE A CLASS EMPLOYEE WITH YOUR CHOICE OF ATTRIBUTES AND FUNCTIONS...
write a C++ program to CREATE A CLASS EMPLOYEE WITH YOUR CHOICE OF ATTRIBUTES AND FUNCTIONS COVERING THE FOLLOWING POINTS: 1) COUNTING NUMBER OF OBJECTS CREATED ( NO OBJECT ARRAY TO BE USED) USING ROLE OF STATIC MEMBER 2) SHOWING THE VALID INVALID STATEMENTS IN CASE OF STATIC MEMBER WITH NON STATIC MEMBER FUNCTION, NON STATIC MEMBERS OF CLASS WITH STATIC MEMBER FUNCTION, BOTH STATIC. SHOW THE ERRORS WHERE STATEMENTS ARE INVALID. 3) CALL OF STATIC MEMBER FUNCTION, DECLARATION OF...
create a VHDL program for the Truth Table below. Please make sure to create your code...
create a VHDL program for the Truth Table below. Please make sure to create your code for the simplified circuit. A B C Z 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 0
Please write a java code. Write a generic program for New Home Construction Pricing with the...
Please write a java code. Write a generic program for New Home Construction Pricing with the following specifications. Note, each one of the 2, 3 or 4 bedroom homes are priced with standard type bathrooms. Update to deluxe or premium choice of bathrooms can be ordered by paying the difference in prices.    Types of homes Price 2 bedroom, 2 bathroom (standard type) and 1 car garage home = $350,000 3 bedroom, 2 bathroom (standard type) and 2 car garage...
Write a javascript program according to the follow requirements: Create a function that converts Fahrenheit to...
Write a javascript program according to the follow requirements: Create a function that converts Fahrenheit to Celsius. It takes a single argument which represents degrees in Fahrenheit. It converts it and returns the degrees in Celsius. Create another function that converts Celsius to Fahrenheit. It takes a argument in Celsius and returns the degrees in Fahrenheit. Implement the function convert(isFtoC, from, to) below. It takes the following three arguments: isFtoC: a boolean that is true if degrees must be converted...
Please write in beginner level PYTHON code! Your job is to write a Python program that...
Please write in beginner level PYTHON code! Your job is to write a Python program that asks the user to make one of two choices: destruct or construct. - If the user chooses to destruct, prompt them for an alternade, and then output the 2 words from that alternade. - If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. - You must enforce that the users enter real...
Please take the code below and add some javascript to it. Please use javascript inline. Please...
Please take the code below and add some javascript to it. Please use javascript inline. Please be sure to specify within the webpage with something like 'Click here' too show what was done and how to activate it. Please post in a format that can be directly copied. Thank you in advance HINT: add some fun widgets to the page index-css.html: <!DOCTYPE html> <html lang="en"> <head> <!-- title for web page --> <title>Index-CSS Page</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1">...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT