Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9194207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:21:12+00:00 2026-06-17T21:21:12+00:00

I have created a simple site that reads a database table and displays it

  • 0

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 & 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.

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.

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.

I have tried several things like using javascript and just can’t wrap my head around it?
Can I get some help?

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.io.*, java.util.*, java.sql.*"%>
<%@page import="oracle.jdbc.driver.OracleConnection" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script language="javascript">

    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;
        }
    }
    </script>
</head>

<body>
    <br><br>
    <form method="post" name="form">
        <table id="data" border="1">
        <tr>
            <th>Selected</th>
            <th>Name</th>
            <th>Address</th>
            <th>Contact No</th>
            <th>Email</th>
            <th>Select</th>
        </tr>
        <%
        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");
        %> 
        <%
            while(rs.next()) {
        %>
            <tr>
                <td></td>
                <td><%=rs.getString(2)%></td>
                <td><%=rs.getString(3)%></td>
                <td><%=rs.getString(4)%></td>
                <td><%=rs.getString(5)%></td>
                <td><input type="button" name="edit" value="Edit" style="background-color:#49743D;font-weight:bold;color:#ffffff;" onclick="editRecord(<%=rs.getString(1)%>);" /></td>
                <td><input type="button" name="select" value="Select" style="background-color:#49743D;font-weight:bold;color:#ffffff;" onclick="selectRecord(<%=rs.getString(1)%>, this);" /></td>
            </tr>
        <%
            }
        %>
        <%
        }
        catch(Exception e){
            e.printStackTrace();
        }
        %>

        </table>
    </form>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:21:13+00:00Added an answer on June 17, 2026 at 9:21 pm
     <script language="javascript">
    
        function editRecord(id) {
            var f=document.form;
            f.method="post";
            f.action='edit.jsp?id='+id;
            f.submit();
        }
    
        function selectRecord(id, btn, i) {
         //Here goes the code to display image
            var images = document.getElementsByName("selectImg");
            for(var i=0;i<images.length;i++){
                if(images[i].id!="img_"+id)
                   images[i].style.display="None";
                else
                   images[i].style.display="Block";
             }
         //End
            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;
            }
        }
        </script>
    

    You need to put a hidden div with image in first column.

        <%
            while(rs.next()) {
        %>
            <tr>
                <td><div name="selectImg" id="img_<%=rs.getString(1)%>">
                    <img src="path_to_image"></div></td>
                <td><%=rs.getString(2)%></td>
                <td><%=rs.getString(3)%></td>
                <td><%=rs.getString(4)%></td>
                <td><%=rs.getString(5)%></td>
                <td><input type="button" name="edit" value="Edit" style="background-color:#49743D;font-weight:bold;color:#ffffff;" onclick="editRecord(<%=rs.getString(1)%>);" /></td>
                <td><input type="button" name="select" value="Select" style="background-color:#49743D;font-weight:bold;color:#ffffff;" onclick="selectRecord(<%=rs.getString(1)%>, this);" /></td>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a simple web app/form using google app engine. the site is
I have created an employee spotlight webpart on our SharePoint site that randomly selects
I have created a custom jQuery plugin that does some simple image resizing for
i have some very simple js (i'm still learning) that basically reads the elements
My problem is that I created a simple application where I have webrowser control.
Could someone help me on this, I have created simple web services using axis2
How to manually create Friendly URLs? (PHP) So I have created simple php file
I am new to Repository concept and get some questions. I have created simple
I have created the simple web service. Code: [ServiceContract] public interface ITsdxService { [OperationContract]
I have created this simple program to learn shared_ptr using namespace std; #define Yes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.