title: JavaScript Form Validation Not working properly
body: <p>This is my HTML/Javascript Code.I am submitting the filled form to a Servlet. There seems to some problem with the form validation. I am not able to figure out why. It is supposed to prompt me to enter a new value if I enter 0 in textbox2 and select Divide from the drop down list box. But it doesn't and the form is submitted without any prompting to the servlet which throws Exception due to division by zero. </p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;A simple calculator&lt;/title&gt;
  &lt;script language="text/javascript"&gt;
  function validate(b,op)
  {
      var newval=b;           
      if(b=="0"&amp;&amp;op=="/")
             newval=prompt("Enter a non-zero value for B:",1);
      document.CalculatorForm.textbox2.value=newval;  
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form name="CalculatorForm" method="get" action="http://localhost:8080/hello/CalculatorServlet" onsubmit="validate(this.textbox2.value,this.dropdown.options[this.dropdown.selectedIndex].value);"&gt;
  A:&lt;input type="text" name="textbox1" id="T1" /&gt;&lt;br&gt;
  B:&lt;input type="text" name="textbox2" id="T2" /&gt;&lt;br&gt;
  Operation&lt;br&gt;
  &lt;select name="dropdown" id="dd"&gt;
  &lt;option value="+"&gt;Add&lt;/option&gt;
  &lt;option value="-"&gt;Subtract&lt;/option&gt;
  &lt;option value="*"&gt;Multiply&lt;/option&gt;
  &lt;option value="/"&gt;Divide&lt;/option&gt;
  &lt;/select&gt;
  &lt;br&gt;
  &lt;input type="submit" value="compute"/&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>