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.ut il.*" %>
<%@ page language="java" %>
<%@ page import="java.sq l.*" %>
<HTML>
<head>
<H1>FAQ</H1>
<% String two; %>
<script type="text/javascript">
function myfun()
{
var category=docume nt.getElementBy Id("category") ;
document.getEle mentById("opt") .value=category .options[category.select edIndex].text;
form1.submit();
}
function refresh()
{
var indexOfcombobox = document.form1. opt1.value;
sel = document.form1. category;
for (i=0; i<document.form 1.category.opti ons.length; i++) {
if (sel.options[i].text ==indexOfcombob ox ) {
document.form1. category.select edIndex = 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("Hh h"+one);
Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
conn=DriverMana ger.getConnecti on("jdbc:odbc:m an","scott","ti ger");
statement= conn.createStat ement();
ResultSet rs = statement.execu teQuery("SELECT DISTinCT name FROM LOGIN" );
%>
<OPTION VALUE='nochoice '>Please choose a category</OPTION>";
<%while(rs.next ()) {
nameselection = rs.getString("n ame");%>
<OPTION value ="optcategory"> <%out.println(n ameselection);% >
</OPTION>
<% } %>
</SELECT> </div>
<%
String sql1 = "SELECT * from login where name='"+request .getParameter(" opt")+"' ";
rs1=statement.e xecuteQuery(sql 1);
%>
<% while (rs1.next())
{
String val1=rs1.getStr ing("name");
String val2=rs1.getStr ing("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
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.ut il.*" %>
<%@ page language="java" %>
<%@ page import="java.sq l.*" %>
<HTML>
<head>
<H1>FAQ</H1>
<% String two; %>
<script type="text/javascript">
function myfun()
{
var category=docume nt.getElementBy Id("category") ;
document.getEle mentById("opt") .value=category .options[category.select edIndex].text;
form1.submit();
}
function refresh()
{
var indexOfcombobox = document.form1. opt1.value;
sel = document.form1. category;
for (i=0; i<document.form 1.category.opti ons.length; i++) {
if (sel.options[i].text ==indexOfcombob ox ) {
document.form1. category.select edIndex = 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("Hh h"+one);
Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
conn=DriverMana ger.getConnecti on("jdbc:odbc:m an","scott","ti ger");
statement= conn.createStat ement();
ResultSet rs = statement.execu teQuery("SELECT DISTinCT name FROM LOGIN" );
%>
<OPTION VALUE='nochoice '>Please choose a category</OPTION>";
<%while(rs.next ()) {
nameselection = rs.getString("n ame");%>
<OPTION value ="optcategory"> <%out.println(n ameselection);% >
</OPTION>
<% } %>
</SELECT> </div>
<%
String sql1 = "SELECT * from login where name='"+request .getParameter(" opt")+"' ";
rs1=statement.e xecuteQuery(sql 1);
%>
<% while (rs1.next())
{
String val1=rs1.getStr ing("name");
String val2=rs1.getStr ing("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
Comment