
i loaded the the data into the drop down listbox in jsp from access database.now i have to add a check box,if it checked means dropdownlist box carryout the data's,else it should be empty.plz help me..plz sends the code for that in jsp.its very very urgent one....

1)select.jsp:
<%@page import ="java.sql.*" %>
<html>
<head>
<script type="text/javascript">
function showData(){
if (document.form.check.checked==true){
xmlHttp=GetXmlHttpObject()
var url="select2.jsp";
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
}
function stateChanged(){
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("name").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{
xmlHttp=new XMLHttpRequest();
}
catch (e){
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
</head>
<body>
<form name="form">
<br><br>
<input type="checkbox" id="check" onclick="showData();">
<div id='name'>
<b>Select Data</b>
<select name='name' >
<option value='-1'></option>
</select>
</div>
</form>
</body>
</html>
2)select2.jsp:
<%@page import="java.sql.*"%>
<%
String buffer="<select name='name' ><option value='-1'>Select</option>";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:student","","");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from data");
while(rs.next()){
String name=rs.getString("name");
buffer=buffer+"<option value='"+name+"'>"+name+"</option>";
}
buffer=buffer+"</select>";
response.getWriter().println(buffer);
System.out.println(buffer);
}
catch(Exception e){
System.out.println(e);
}
%>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.