title: How to call a JavaScript function from a button onclick in JSP page
body: <pre><code>    &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
          pageEncoding="ISO-8859-1"%&gt;
          &lt;%@page import="java.util.Map" %&gt;
      &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
      &lt;html&gt;
      &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
      &lt;title&gt;Login page&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
       &lt;link rel="stylesheet" type="text/css" href="css/login.css"/&gt;
      &lt;link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" /&gt;
  
      &lt;form action="LoginS" method="post"&gt;  
         &lt;button type="submit"  onclick="javascript:MyFunction();"&gt;Login&lt;/button&gt;
        &lt;div class="container" style="background-color:#f1f1f1"&gt;
          &lt;button type="button" class="cancelbtn"&gt;Cancel&lt;/button&gt;
          &lt;span class="psw"&gt;Forgot &lt;a href="#"&gt;password?&lt;/a&gt;&lt;/span&gt;
        &lt;/div&gt;
  
        &lt;script type="text/javascript"&gt;
      MyFunction(){
                   alert("java Script");
      }
      &lt;/script&gt;
       &lt;/form&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>Above is my code that I'm trying to call JavaScript function from the submit button <code>onclick()</code> event but its showing nothing. Am I doing any wrong in code.</p>
  
  <p>When I click on the button nothing happens. I want the string value in the text box to be printed on the console.</p>