<%@ page import="java.sql.*" %>
<html>
<head>
<script type="text/javascript">
function showUser(user_value)
{
if(document.getElementById("user_id").value!="-1")
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getuser.jsp"
url=url+"?user_id="+user_value
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
else
{
alert("Please Select User Id");
}
}
function stateChanged()
{
document.getElementById("username").value ="";
document.getElementById("user_id").value ="";
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
var showdata = xmlHttp.responseText;
var strar = showdata.split(":");
if(strar.length==1)
{
document.getElementById("user_id").focus();
alert("Please Select User Id");
document.getElementById("username").value =" ";
document.getElementById("user_id").value =" ";
}
else if(strar.length>1)
{
var strname = strar[1];
document.getElementById("User_id").value= strar[2];
document.getElementById("username").value= strar[1];
}
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
</head>
<body>
<form name="user">
<br><br>
<table border="0" width="400px" align="center" bgcolor="#CDFFFF">
<div id="mydiv"></div>
<tr><td><b>Select User Id</b></td><td>
<select name="suser_id" onchange="showUser(this.value);">
<option value="-1">Select</option>
<%
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "user_register";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
int sumcount=0;
Statement st =null;
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
String Query = "select * from knp_usermaster";
st = conn.createStatement();
ResultSet rs = st.executeQuery(Query);
%>
<%
while(rs.next())
{
%>
<option value="<%=rs.getString(1)%>"><%=rs.getString(1)%></option>
<%
}
%>
<%
}
catch (Exception e) {
e.printStackTrace();
}
%>
</select>
</td></tr>
<tr><td><b>User Id:</b></td><td><input type="text" name="user_id" id="user_id" value=""></td></tr>
<tr><td><b>UserName:</b></td><td><input type="text" name="user_name" id="user_name" value=""></td></tr>
</table>
</form>
<table border="0" width="100%" align="center">
<br>
<br>
</table>
</body>
</html>