title: How to call functions through a href in jsp
body: <p>I have <code>jsp</code> code where i fetch data from database in a <code>resultset</code> and pass it in <code>a href</code>. When i click on link i call a function from <code>&lt;script&gt;</code>. Only problem is when i click on the link the result comes and goes. It doesn't stop at that page. Can anyone help me to solve this. My <code>jsp</code> code is:</p>
  
  <pre><code>&lt;%@include file="dbconnection.jsp"%&gt;
  
  &lt;HTML&gt;
  &lt;HEAD&gt;
      &lt;TITLE&gt;
      &lt;/TITLE&gt;
  
  &lt;/HEAD&gt;
  
  &lt;BODY&gt;
      &lt;H1&gt;&lt;/H1&gt;
      &lt;script&gt;
  
  
  function displayData(ctr) {
         //////// Here i want to display data related to that particular link
  
  
  switch (ctr) {
  case 1:
  
      &lt;%ResultSet rs = statement.executeQuery("select CID from categoryConfigTable where parentCID = 'NULL';") ;  %&gt;
      &lt;% 
      int c=0;
       while(rs.next()){ 
          String link=rs.getString(1);
          c++;
      %&gt;
      document.write('&lt;A HREF = "#" ONCLICK="abc(&lt;%=c%&gt;)"&gt;&lt;%=link%&gt;&lt;/A&gt;');
      &lt;% } %&gt;
      document.write('&lt;button onclick="goBack()"&gt; Go Back &lt;/button&gt;');
  
      function goBack() {
          window.history.back()
      }
  
      break;
  case 2:
     alert("function 2");
       break;
  
       }
  }
  
  
  &lt;/script&gt;
   &lt;TABLE&gt;
             &lt;%ResultSet resultset = statement.executeQuery("select DISTINCT title from categoryInfoTable where CID in(select CID from categoryConfigTable where parentCID = 'NULL');") ;%&gt;
              &lt;% 
              int counter=0;
               while(resultset.next()){ 
                  String link=resultset.getString(1);
                  counter++;
              %&gt;
              &lt;TR&gt;
                 &lt;TD&gt;
                     &lt;a onclick="displayData(&lt;%=counter%&gt;)" href="#"&gt;&lt;%=link%&gt;&lt;/a&gt;
                 &lt;/TD&gt; 
              &lt;/TR&gt;
              &lt;% } %&gt;
    &lt;/TABLE&gt;
  &lt;/BODY&gt;
  &lt;/HTML&gt;
  </code></pre>