hi...
I am developing my webproject in which i have 3 campus and each campus has different different courses. In registration form i want two select boxes one for campus and another for course. When i select campus i want to populate appropriate courses from database without page refresh. I have tried one solution but in that solution page will refreshed and then it will populate the course listbox from database but campus list box will removes selected value.. please help me....
my code...............
<%@ page language="java" %> <%@ page import="java.sql.*" %> <%! Connection conn = null; String url = "jdbc:mysql://localhost:3306/jbgroup";; String user = "root"; String pass = "admin"; ResultSet rs =null; Statement st=null; String query=""; String C1="C1"; int mid; %> <% if(request.getParameter("mid")!=null){ mid=Integer.parseInt(request.getParameter("mid")); }else { mid=0; } Class.forName("com.mysql.jdbc.Driver") ; conn = DriverManager.getConnection(url, user, pass); st = conn.createStatement(); rs = st.executeQuery("select * from campus"); %> <html> <head> <script type="text/javascript"> function selectCity(){ var mid=document.getElementById("countryId").selectedIndex; window.location.replace("http://localhost:8080/RASS-JB1.2/listbox.jsp?mid="+mid); } </script> </head> <body> <select id="countryId" name="countryId" onchange="selectCity(this)"> <option value="0">--Please Select--</option> <% while(rs.next()){ %> <option value="<%=rs.getString("CAMPUS_ID")%>"><%=rs.getString("CAMPUS_NAME")%></option> <%}%> </select> <select> <option value="0">--Please Select--</option> <% System.out.println(mid); rs = st.executeQuery("select * from course where CAMPUS_ID='"+C1+""+mid+"'"); while(rs.next()){ %> <option value='<%=rs.getString("COURSE_ID")%>'><%=rs.getString("COURSE_NAME")%></option> <%}%> </select> </body> </html>
Ads