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...
"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...
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">...
Write a simple javascript program using express and node.js to create a simple webpage that can...
Write a simple javascript program using express and node.js to create a simple webpage that can lead to other pages within the program. if possible, Comment everything out so I could understand how every things works.  But basically, server should be hosted on localhost:8000 and should have a simple starting page. Maybe a welcome message, with at least two "links" that goes to a "homepage" and then a "exit" page.
Write a program in C++ Write three new functions, mean() and standard_deviation(). Modify your code to...
Write a program in C++ Write three new functions, mean() and standard_deviation(). Modify your code to call these functions instead of the inline code in your main(). In addition, add error checking for the user input. If the user inputs an incorrect value prompt the user to re-enter the number. The flow of the code should look something like: /** Calculate the mean of a vector of floating point numbers **/ float mean(vector& values) /** Calculate the standard deviation from...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT