title: How to write a database connection in Javascript?
body: <p>I want to connect to a database depending on the data enter in a <code>.jsp</code> form. I do not know how to connect to database in a <code>Javascript</code>.</p>
  
  <p>My code as follows:</p>
  
  <pre><code>&lt;%@ page contentType="text/html; charset=iso-8859-1" language="java" %&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;script&gt;
  function validateForm()
  {
     if(document.frm.username.value=="srinu")
  {
    // conect database here
  }
  else 
  {
    alert("wrong input");
    document.frm.pwd.focus();
    return false;
  }
  }
  </code></pre>
  
  <p>
      
  Body here, i want to connect database based on the details entered in the body.</p>
  
  <pre><code> &lt;body&gt;
  &lt;form name="frm" method="get" action="validateInput.jsp" onSubmit="return validateForm()"&gt;
  &lt;table width="100%" border="0" cellspacing="0" cellpadding="0"&gt;
     &lt;tr&gt;
     &lt;td width="22%"&gt;&amp;nbsp;&lt;/td&gt;
     &lt;td width="78%"&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
     &lt;td&gt;UserName &lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="username" /&gt;&lt;/td&gt;
   &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&lt;input type="submit" name="submit" value="Submit"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>