I ceate a JSP which fetch value from database and displayed it in a table. Now I want to create a click function for the table. Click the row it will display some value. I use a js code for it but when I click the line nothing happened. Can anyone help? Thanks.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page import="SCOfetch.*" %>
<%@ page import="java.util.ArrayList" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>First Page</title>
<% JCOtest connection1 = new JCOtest(); %>
<%
ArrayList<CompanyRecord> list = new ArrayList<CompanyRecord>();
list = connection1.step4QueryTable();
%>
//*This is the click function*
<script language="javascript">
function showBgc(idn){
alert (idn);
}
</script>
</head>
<body>
<c:set var="greeting" value="Hello, World!"/>
<!-- <img id="image-1" alt="" src="img/snow.jpg" width="300" height="300"/> -->
//This is the result table
<table>
<%
int size=list.size();
for(int i=0;i<size;i++){
CompanyRecord news =(CompanyRecord)list.get(i);
%>
<tr>
<td onclick="showBgc(i)"><%=news.getValue("Code") %></td>
<td onclick="showBgc(i)"><%=news.getValue("Name") %></td>
</tr><%
}
%>
</table>
</body>
</html>
And I debug it in IE. the html is like
<tr>
<td onclick="showBgc(i)">DE01</td>
<td onclick="showBgc(i)">Country Template DE</td>
</tr>
and the error is i not defined.