title: showing database value with an image using JSP
body: <p>I have created a simple site that reads a database table and displays it in a html table in the browser.
  I have a button that allows for the table to be altered, saved &amp; then automatically forwarded to the homepage with the updated table.
  I also have a select button with which the user can select that particular row and it updates a column in the table.</p>
  
  <p>My problem is that I need a way to show which row has been selected.
  I prefer to have a column in the HTML table that shows an image as to which one is selected. </p>
  
  <p>Here is my homepage where the database table is being displayed.
  In the left column of the html is where I would like to add an image if that row is selected.</p>
  
  <p>I have tried several things like using javascript and just can't wrap my head around it?
  Can I get some help?</p>
  
  
  
  <pre class="lang-html prettyprint-override"><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;%@page import="java.io.*, java.util.*, java.sql.*"%&gt;
  &lt;%@page import="oracle.jdbc.driver.OracleConnection" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
      &lt;script language="javascript"&gt;
  
      function editRecord(id) {
          var f=document.form;
          f.method="post";
          f.action='edit.jsp?id='+id;
          f.submit();
      }
  
      function selectRecord(id, btn, i) {
          var f=document.form;
          f.method="post";
          f.action='select.jsp?id='+id;
          f.submit();
  
          if(!btn.style) {
              alert("not supported");
              return;
          } else{
              btn.style.background = "red";
              return;
          }
      }
      &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;br&gt;&lt;br&gt;
      &lt;form method="post" name="form"&gt;
          &lt;table id="data" border="1"&gt;
          &lt;tr&gt;
              &lt;th&gt;Selected&lt;/th&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;Address&lt;/th&gt;
              &lt;th&gt;Contact No&lt;/th&gt;
              &lt;th&gt;Email&lt;/th&gt;
              &lt;th&gt;Select&lt;/th&gt;
          &lt;/tr&gt;
          &lt;%
          int sumcount=0;
          ResultSet rs = null;
          Connection con = null;
          Statement st = null;
  
          try {
              DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
              con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "username", "password");
  
              st = con.createStatement();
              rs = st.executeQuery("SELECT * FROM employee");
          %&gt; 
          &lt;%
              while(rs.next()) {
          %&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;%=rs.getString(2)%&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;%=rs.getString(3)%&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;%=rs.getString(4)%&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;%=rs.getString(5)%&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="button" name="edit" value="Edit" style="background-color:#49743D;font-weight:bold;color:#ffffff;" onclick="editRecord(&lt;%=rs.getString(1)%&gt;);" /&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="button" name="select" value="Select" style="background-color:#49743D;font-weight:bold;color:#ffffff;" onclick="selectRecord(&lt;%=rs.getString(1)%&gt;, this);" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;%
              }
          %&gt;
          &lt;%
          }
          catch(Exception e){
              e.printStackTrace();
          }
          %&gt;
  
          &lt;/table&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>