Get value in text box from db by changing the value of cmbbox using jsp
--> I got solution for that the code is below.
I am new to use jsp/servlate.
I got success but some problem when i change the value of combobox once again than it will not show me value.
every time i have to refresh the page. If any one have idea then let me know.
1) test.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script language="JavaScript">
function callServlet(){
window.ifrm.document.temp_form.selectValue.value = document.form.Project_ID.value;
window.ifrm.document.temp_form.submit();
}
</script>
</head>
<body>
<form method=post name=form action="">
<iframe src="temp.html" name="ifrm" width=0 height=0></iframe>
<select name="Project_ID" onchange="callServlet()">
<option value="" selected></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
<input type="text" name="txt" value="" />
</body>
</html>
2)db.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language="java" import="java.sql.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%! ResultSet rs = null;%>
<%
String db=null;
try
{
Connection con = null;
PreparedStatement pst = null;
String val=request.getParameter("selectValue");
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection ("jdbc:oracle:thin:@localhost:1521:<dbname>", "<username>", "<password>");
pst= con.prepareStatement("select subjname from subjmast where subjcode= '"+val+"'");
rs=pst.executeQuery();
while (rs.next())
db=rs.getString(1);
{
out.print("<script>window.parent.document.form.txt.value ='" + db + "';</script>");
}
}catch(Exception e){System.out.println("Error"+e);}
%>
</body>
</html>
3) temp.html
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form method=post name=temp_form action="db.jsp">
<input type="text" name="selectValue"></form>
</body>
</html>
in above test.jsp has hidden iframe which get value from test.jsp and call the db.jsp from that get result and give back to the test.jsp.