In dropdown i am retriving value from the backend.
For eg: in the dropdown list the value selected are employee id..then i want to disply the emp name,job etc in the textbox. If i select a optino in dropdown menu then that id name etc shuld come in the textbox without refreshing the page...
plz any help.......
<%@ page import="java.util.*" %>
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<HTML>
<head>
<H1>FAQ</H1>
<% String two; %>
<script type="text/javascript">
function myfun()
{
var category=document.getElementById("category");
document.getElementById("opt").value=category.opti ons[category.selectedIndex].text;
form1.submit();
}
function refresh()
{
var indexOfcombobox = document.form1.opt1.value;
sel = document.form1.category;
for (i=0; i<document.form1.category.options.length; i++) {
if (sel.options[i].text ==indexOfcombobox ) {
document.form1.category.selectedIndex = i;
}
}
}
</script>
</head>
<FORM name="form1" method=post action="">
<body onload="refresh()">
<input type=hidden name=opt>
<%
String nameselection = null;
String one=null;
ResultSet rs1;
Statement statement,st1;
Connection conn;
%>
<div>
<SELECT NAME="Category" id="Category" value="opt" onChange="myfun()">
<%
out.println("Hhh"+one);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:man"," scott","tiger");
statement= conn.createStatement();
ResultSet rs = statement.executeQuery("SELECT DISTinCT name FROM LOGIN" );
%>
<OPTION VALUE='nochoice'>Please choose a category</OPTION>";
<%while(rs.next()) {
nameselection = rs.getString("name");%>
<OPTION value ="optcategory"><%out.println(nameselection);%>
</OPTION>
<% } %>
</SELECT> </div>
<%
String sql1 = "SELECT * from login where name='"+request.getParameter("opt")+"' ";
rs1=statement.executeQuery(sql1);
%>
<% while (rs1.next())
{
String val1=rs1.getString("name");
String val2=rs1.getString("pwd");
out.println ("<input type=text name=opt1 value='" + val1 + "'>");
out.println ("<input type=text name=opt2 value='" + val2 + "'>");
}%>
</FORM> </body>
</HTML>
Am getting the selected values but the choice box is also refreshing and coming to the default value...plz any help