java script varable in jsp
In our project we need to create form with two Fields in such way that first field is combo box and second is textbox. when we select any item in combobox by that selected value we need fetch related dat from data base and display on textbox.
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%!
Connection con =null;
PreparedStatement pst =null;
ResultSet rs=null;
%>
<html>
<head>
<title>Form</title>
<script language="javascript">
function func()
{
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:yourdsn"," "," ");
%>
var str=f1.ccode.value;
<%
pst=con.prepareStatement("Select course_name from course_master where course_id=?);
String ss=(String)%>str<%;
pst.setString(1,ss);
rs=pst.executeQuery();
if(rs.next())
String cn=rs.getString(1);
%>
f1.cname.value="<%=cn%>";
}
</script>
</head>
<body>
<form name="f1">
<table align="center">
<tr><td><b>Course Code</b></td><td><select name="ccode" size="1" onchange="func()">
<option>001</option><option>002</option><option>003</option><option>004</option>
</select>
<b>Starting Date</b><input id"Text" type="text" name="cname" /></td></tr>
</table>
</form>
</body>
</html>

