title: HTML/Javascript calculator with dropdown
body: <p>
          </p>
  
  <pre><code>       function calculate() {
              try
              {
              var value1 = parseInt(validate(document.getElementById("value1").value.trim()));
              var value2 = parseInt(validate(document.getElementById("value2").value.trim()));
              document.getElementById("result").value = operate(value1, value2);
              }
              catch (err) {
                  alert("There was a problem: " + err.messaqge);
              }
          }
              catch (err) {
                  alert("There was a problem: " + err.messaqge);
              }
          }
  
          function operate(value1, value2) {
              if (operator == addition) {
                  return value1 + value2;
              } else if (operator == subtraction) {
                  return value1 - value2;
              } else if (operator == division) {
                  return value1 / value2;
              } else if (operator == multiplication) {
                  return value1 * value2;
              }
  
              function validate(value) {
                  if (value == null || value == "") {
                      alert("Required Field");
                      return 0;
                  } else if (isNaN(value)) {
                      alert("Must be a Number Field");
                      return 0;
                  } else return value;
              }
          }
      &lt;/script&gt;
      &lt;title&gt;Title Bar&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;h2&gt;Calculator&lt;/h2&gt;
        &lt;table border="1"&gt;
            &lt;tr&gt;
              &lt;td&gt;Value 1: &lt;/td&gt;
              &lt;td&gt;&lt;input type="text" id="value1" name="value1"/&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;Value 2: &lt;/td&gt;
              &lt;td&gt;&lt;input type="text" id="value2" name="value2" /&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;Operator: &lt;/td&gt;
              &lt;td&gt;&lt;select id="operator"&gt;
              &lt;option value="Add"&gt;+&lt;/option&gt;
              &lt;option value="Subtract"&gt;-&lt;/option&gt;
              &lt;option value="Multiply"&gt;*&lt;/option&gt;
              &lt;option value="Divide"&gt;/&lt;/option&gt;
              &lt;/select&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;Result: &lt;/td&gt;
              &lt;td&gt;&lt;input type="text" id="result" name="result" /&gt;&lt;/td&gt;
            &lt;/tr&gt;
        &lt;/table&gt;
        &lt;input type="submit" id="btn_sub" name="btn_sub" value="Submit" onclick="calculate()" /&gt;
        &lt;input type="reset" id="btn_res" name="btn_res" value="Reset" /&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is for a really basic calculator program. I had it as just addition and it was working, but I am trying to add a dropdown so I can do different operations, and I'm not able to get this to work.  It's gotta be just the operate function or the 3rd line in the calculate function, because everything else was working when it was just for addition.</p>