JavaScript How to get value of option of a select element and use it in a calculation? value option select jquery,value option select,value option select

I'm doing an example for this javascript textbook and it's a simple calculator. There are two input (number) tags where the user selects a number and a select tag with options for a modifier (see code).

<input type="number" value="2" id='num1'>
<select id="operation">
    <option>+</option>
    <option>-</option>
    <option>*</option>
    <option>/</option>
    <option>%</option>
</select>
<input type="number" value="2" id='num2'> =
<input type='text' readonly>
<br>
<input id="button1" type="button" value="Do It!">

What I have to do is get the values of both the numbers and then calculate the operation based on which modifier is selected in the options.

window.addEventListener("load", function() {
    document.getElementById("button1").onclick = function(event) {
        var num1 = document.getElementById("num1").value;
        var num2 = document.getElementById("num2").value;
        var mod = document.getElementById("operation").selectedIndex;
    }
});

However, I don't understand how to do the calculation with the modifier. Would I need an if statement where it checks what value the mod has and then depending on that it does a certain calculation? Or is there a simpler way to just get the modifier and do a certain calculation that way?

Answer:1

Please find my JSON below: I want to identify unique user and get the corresponding unique users value count. For Example: userID: user1 has 3 records and I want to form the JSON like below: ...

Please find my JSON below: I want to identify unique user and get the corresponding unique users value count. For Example: userID: user1 has 3 records and I want to form the JSON like below: ...

  1. identify duplicate values in excel
  2. identify duplicate values in r
  3. identify duplicate values in google sheets
  4. identify duplicate values in two columns
  5. identify duplicate values in sql
  6. identify duplicate values in pandas
  7. identify duplicate values in a column excel
  8. identify duplicate values in two columns excel
  9. identify duplicate values in excel formula
  10. identify duplicate values in multiple columns in excel

I'm working in a React.js project which I need to import some JavaScript in others, and some others I have to export it. For example I have A.js which needs some library: var EventEmitter = require('...

I'm working in a React.js project which I need to import some JavaScript in others, and some others I have to export it. For example I have A.js which needs some library: var EventEmitter = require('...

  1. import export modules javascript
  2. import export modules
  3. import export modules js
  4. import export modules angular
  5. import export module es6
  6. import export module typescript
  7. import-export module nodejs
  8. import export module python
  9. import_export module django
  10. import export module opencart
  11. import export module prestashop
  12. import export module vba
  13. import export module drupal 7

I need to get enum values of field in schema I have schema: let adminSchema = new Schema({ login: { type: String, unique: true, required: true, minlength: 5, maxlength: 300 }, ...

I need to get enum values of field in schema I have schema: let adminSchema = new Schema({ login: { type: String, unique: true, required: true, minlength: 5, maxlength: 300 }, ...

I have a dot net page that shows/hides panels. when I set compatibility view "display all websites in Compatibility View" the Last panels dynamically generated link does not display but it does exist....

I have a dot net page that shows/hides panels. when I set compatibility view "display all websites in Compatibility View" the Last panels dynamically generated link does not display but it does exist....