title: How to get an input value dynamically and perform arithmetic operations using javascript
body: <p>I  have created two input text fields by which the user have to give two values. Using javascript, I need to get those values perform addition, subtraction, multiplication and division based on the checkbox checked. How to do that?</p>
  
  <p>Here is my code..</p>
  
  <pre><code>    &lt;html&gt;
          &lt;head&gt;
              &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
              &lt;title&gt;JS Assignment&lt;/title&gt;
              &lt;script&gt;
              function changeCheckBox() {
           try {
  
               var max = document.myform.check.length;
               var count = 0;
  
               for (var i = 0; i &lt; max; i++) {
                   if (document.myform.check[i].checked == true) {
                       count++;
                       serNoChecked = i;
                   }
               }
               if (count == 1) {
                   for (var i = 0; i &lt; max; i++) {
                       if (document.myform.check[i].checked == false) {
                           document.myform.check[i].disabled = true;
                       }
                   }
               } else if (count == 0) {
                   for (var i = 0; i &lt; max; i++) {
                       document.myform.check[i].disabled = false;
                   }
               }
  
               if (null == max) return false;
               if (count == 0) {
                   return true;
               } else if (count &gt; 0) {
                   return false;
               }
  
           } catch (e) {
               alert(e.message);
           }
       }
  &lt;/script&gt;
       &lt;script type="text/javascript"&gt;
                  function arith()
                  {  
                  var number1 = document.getElementById('num1').value;
                  var number2 = document.getElementById('num2').value;   
                  x=num1 + num2;
                  var demoP=document.getElementById("demo")
                  demoP.innerHTML="x=" + x;
                  }         
      &lt;/script&gt;
          &lt;/head&gt;
          &lt;body background="photo.jpg" onload="arith()"&gt;
              &lt;h3&gt;Simple JavaScript Arithmetic Operations&lt;/h3&gt;
              &lt;form name="myform" method="get"&gt;
              Value 1 &lt;input type ="text" id="num1"&gt; &lt;br&gt;&lt;br&gt;
              Value 2 &lt;input type="text" id="num2"&gt; &lt;br&gt;&lt;br&gt;
              &lt;input type="checkbox" name="check" value="check1" id="check1" onclick="changeCheckBox()"&gt;Addition&lt;br&gt;
              &lt;input type="checkbox" name="check" value="check2" id="check2" onclick="changeCheckBox()"&gt;Subtraction&lt;br&gt;
              &lt;input type="checkbox" name="check" value="check3" id="check3" onclick="changeCheckBox()"&gt;Multiplication&lt;br&gt;
              &lt;input type="checkbox" name="check" value="check4" id="check4" onclick="changeCheckBox()"&gt;Division&lt;br&gt;&lt;br&gt;
              &lt;input type="submit" value="Submit"&gt;
              &lt;/form&gt;
              &lt;p id="demo"&gt;&lt;/p&gt;  
          &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>