title: Add onsubmit event to call JS function in MVC3
body: <p>I have a problem with calling JS method from form in MVC3 project: I have a "search"page without forms with two buttons - Search and Cancel. Click on search runs JS function runSearch in ProductDefinition. </p>
  
  <pre><code>&lt;div id="productSearch-dialog" class="modal fade" style="width: 1000px; display: none"&gt;
  &lt;div class="modal-header"&gt;
      &lt;button class="close" aria-hidden="true" data-dismiss="modal" type="button"&gt;×&lt;/button&gt;
      &lt;h3&gt;Search Results&lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="modal-body" style="height: 650px;"&gt;
      &lt;div&gt;
          &lt;input id="inputname" type="text" /&gt;&lt;font class="red-font" id="lblrequired" style="display: none"&gt;*&lt;/font&gt;
      &lt;/div&gt;
      &lt;div id="searchresultcontain" class="grid"&gt;
      &lt;/div&gt;
      &lt;div id="Pagination" class="pagination"&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="modal-footer"&gt;
      &lt;button class="btn btn-primary" onclick="productDefinition.runSearch();"&gt;Search&lt;/button&gt;
      &lt;button class="btn btn-primary" data-dismiss="modal"&gt;Cancel&lt;/button&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>How can I run this JS method (runSearch) when I press ? As far as I understand, this will be onsubmit event which is form event, so I am need to add form element with onsubmit property. I tried surrounding input field with BeginForm helper method: </p>
  
  <pre><code>@using (Html.BeginForm(new { onsubmit = "productDefinition.runSearch();" }))
  {
      &lt;input id="inputname" type="text" /&gt;&lt;font class="red-font" id="lblrequired" style="display: none"&gt;*&lt;/font&gt;
      &lt;input type="submit" value="Submit" style="visibility: hidden" /&gt;
  }
  </code></pre>
  
  <p>but it does not seem to be working - when I press enter I for some reason get source of the page and arrive at localhost/?onsubmit=productDefinition.runSearch() URL.<br>
  What can be the source of the problem and how can I get the same behaviour for onsubmit as for onclick?</p>