Populate listbox according to selection value from another selectbox

Ads
 

Populate listbox according to selection value from another selectbox

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>
View Answers

Ads









Related Tutorials/Questions & Answers:
Populate listbox according to selection value from another selectbox
Populate listbox according to selection value from another selectbox  ... listbox from database but campus list box will removes selected value.. please help... for campus and another for course. When i select campus i want to populate
Populate value into HTML page
Populate value into HTML page  Hi, How to populate values from one html page table to another html page..? Thanks
Advertisements
I want to Populate ComBobox value from database that combox is Itemrenderer of DataGrid.
I want to Populate ComBobox value from database that combox is Itemrenderer of DataGrid.  I want to Populate ComBobox value from database that combox is Itemrenderer of DataGrid
how to retrieve the id value itself from the access database to drop down listbox in jsp
how to retrieve the id value itself from the access database to drop down listbox in jsp  how to retrieves the id which is an int datatype, from...   <%@page import="java.sql.*"%> <select> <option value
how to display data from database according to entered value in search field
how to display data from database according to entered value in search...("SELECT M.MEMBER_ID, M.FNAME,M.LNAME,M.AGE,B.HEIGHT,B.WEIGHT, B.BMI_VALUE FROM...;/b></td> <td>: <input type="text" name="bmi_value" id="BMI
Populate values from html to another html
Populate values from html to another html In this tutorial, you will learn how to send values from one html page to another. Here, we have create a html... on another html page. page1.html: <html> <form type=get action="
Problem passing a value from one jsp to another using href
Problem passing a value from one jsp to another using href  first page.jsp <a href="common.jsp?param=<%l.get(k).parentname%>">...);%> since url print a common.jsp?param=Arts but attr return a null value
Problem passing a value from one jsp to another using href
Problem passing a value from one jsp to another using href  first page.jsp <a href="common.jsp?param=<%l.get(k).parentname%>">...);%> since url print a common.jsp?param=Arts but attr return a null value
change color according to the database value
change color according to the database value  any one know how to get values from database ( 1 or 0 ) and according to that change the color ( red or green) of given list
to enter into a particular page only if the username,password and listbox value mtches
to enter into a particular page only if the username,password and listbox value... in to his page only if the username, password and the listbox value(user type... in the database. here i have a problem in checking the listbox value
Get JTextField value from another class
Get JTextField value from another class   ... value from other class. For this, we have created two classes ClassA.java and ClassB.java. In ClassA, we have defined a textbox 'text1' that will get the value from
passing textbox value from one page to another page using html n javascript
passing textbox value from one page to another page using html n javascript  on button onclick event pass text box value and i want to pass value...;/td> </tr> <tr> <td colspan=2><input type=submit value
Populate a combo box using data from a database
Populate a combo box using data from a database  Hi Guys, In need... to populate the first one, and then how to send the data off to a servlet and preform... to the client using ajax, and then populate the combo box, I must'nt reload
Populate dropdown menu from database using jsp and servlet
Populate dropdown menu from database using jsp and servlet  please i need code to populate dropdown menu from mysql database using jsp and servlet. thanks
how to know which jList is selected and according to that fetch the value
is selected so that i get the value of employee_id from the correct jList (i.e which...how to know which jList is selected and according to that fetch the value ... , jList4) in 4 different tabs in frame. Each List has the value of employee_id
How to create textbox on combo value selection using javacsript in jsp?
How to create textbox on combo value selection using javacsript in jsp?  dynamically create textbox on combo value selection. when select multiple values then create multiple textboxes
Show a hidden frame previously from another from
Show a hidden frame previously from another from  How can i show a hidden frame previously by this code: jframe_name.hide(); and make it visible from another frame i'm waiting for the answer, and i'll be thankfull
Use varibles from another class
Use varibles from another class  **I have two classes. class 1:** public class askfigures extends JFrame { method from class1: public void... in another class. another class: public class Askvalues extends JFrame
returning a value from Threads
returning a value from Threads  Hello I have worker pattern that uses... when returning a value using Future.I have code snippet below: ExecutorService... the jdeque so that I can pass it on to another process but I have a problem
Reading Value From console
Reading Value From console  In case of String data Type readLine method of DataInputStream class read complete line of the given string but the next method of Scanner class doesn't read the complete line of String. why
Reading Value From console
Reading Value From console  In case of String data Type readLine method of DataInputStream class read complete line of the given string but the next method of Scanner class doesn't read the complete line of String. why
Return Value from One Form
Return Value from One Form  I have two buttons in main form client... is there.when i click dedupe button another form will open. i want to get a field value of dedupe form and use in bank form..how to do
calling one jsp from another jsp page
calling one jsp from another jsp page  need coding for calling one jsp from another jsp including the xml file.Its urgent
passing value from javascript popup
passing value from javascript popup  How to take user input and pass that input value using popup in Javascript
my table should be reseted to new value upon the selection of the combo box..
my table should be reseted to new value upon the selection of the combo box...(true); initComponents(); try { rs= st.executeQuery("SELECT cname FROM pur...); sc1.setBounds(20, 160, 620, 380); } /** * This method is called from within
Subtract a value in the database from java
Subtract a value in the database from java   Hi, i want to know how to subtract a value on a database. im using JDBC connection from access and i want to decrement the value of table "quantity" of 1 each time it passes a loop my
mysql select into table from another table example
mysql select into table from another table example  Can you suggest the correct example of select into table from another table example in MySQL... from one table into another table. Check the example at MySQLselect into new
passing data from one jframe to another
passing data from one jframe to another  I have two JFrame,built by using the GUI Editor netbeans 6.9.i have to pass a data from a Jtextfield in the first Jframe to another JLabel in the other JFrame.Can you please help me,how
How to obtain the selected data item from a list box when listbox contains objects wrapped under Arraylist?
How to obtain the selected data item from a list box when listbox contains... and a text box. I am sending an Array List object from a servlet to this jsp page. The listbox gets populated by the data contained in the arraylist. Now, I
How to navigate from one jsf to another in eclipse
How to navigate from one jsf to another in eclipse  Hi there is my...; <h:outputText value="USER DETAILS FORM"> </h:outputText> </b>... id="UserDetail"> <h:panelGrid columns="2"> <h:outputText value
File copy from one directory to another in java
File copy from one directory to another in java  I am trying to find very good code example for copying a file from one directory to another... from a directory to another directory. How to achieve this? Is there any API

Ads