Populate listbox according to selection value from another selectbox

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









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 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
get the value from another class - Java Beginners
get the value from another class  Hello to all, I have stupid question. I have main.java and ConfigXML.java(read my config xml file). Code from...)).getNodeValue().trim(); from my ConfigXML.java in main.java. Sorry for my bad
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
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
navigating the value of JTextField from one JFrame to another - Swing AWT
navigating the value of JTextField from one JFrame to another  hello I m doing one project where I m retriving the data from databse in JTextField... button all the details of an item of JTextField will be displayed in another
navigating the value of JTextField from one JFrame to another - Swing AWT
navigating the value of JTextField from one JFrame to another  Hello... to retrive the new records from database using the the value of JForm1... the records from database using up and down keys of keyboard? And also I wanted
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
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
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 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 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
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
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. (adsbygoogle = window.adsbygoogle || []).push
jsp listbox - Java Beginners
jsp listbox  thanks for your earlier post. I have one list box filled from the datebase. i want my second listbox to be filled from the database based on the selection of first list box. without refreshing my jsp page
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
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
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
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
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
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
selectbox - Framework
selectbox  Hello Roseindia, I want a favour from you..currently in my project i am using struts2.Now i want dyanmic database values add to select box in struts2 .....I don't want use scriptlets in jsp..give me ur valuable
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
Values to listbox
Values to listbox  I have two textboxes by the name street and city.I have an add button and a name listbox. When I enter street and city and press the add button ,all the names of the people residing there are listed in listbox
passing value from javascript popup
passing value from javascript popup  How to take user input and pass that input value using popup in Javascript
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
passing from 1 jsp to another - JSP-Servlet
passing from 1 jsp to another  Hi Sir, What are the ways and means of passing from 1 jsp page to another page.what are the different types of methods?  Hi Friend, You can use tag,sedRedirect() method
how to pass a string from one class to another
string from one class to another. import java.util.*; class A{ static String... String from class A: "+b); } }   Here is another example of passing string from one class to another. import java.io.*; class Class1 { public
update one table from another table
update one table from another table  hello, i need to update one table fields by using another table fields. I have to tables Products.... for example TotalQuantity field from Products table should be updated if i
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
Need to access data from another application
Need to access data from another application  Hi Tech masters, I want to develop a reporting application.for that I need to access data from a third party application. I want to access data from a software called service
How to forward the control from one jsp to another?
How to forward the control from one jsp to another?  Hi! This is Prasad Jandrajupalli. I have the 3 JSP's, but I want communicate with each... is not communicate with the Third JSP. I want forward the control from first jsp to second
populate dropdown box
populate dropdown box  hi, Is there any ways in which i can populate my dropdown menu with values from 1 to n (n = the value stored in database)using java script or jsp, either is fine? Ex: If value corresponding to selected
Read the value from XML in java
Read the value from XML in java  Hi, i have an XML... the permissions on that file.So how can i read that value. This is little urgent.... <param name="file" value="D:/Lakki
copying data from one table to another
copying data from one table to another  i need to copy data from one table to another table.. i.e the 1st eid of employee table must be copied to the 1st eid in appusers table, 2nd eid of employee to the 2nd eid of appusers
Data Conversion from int to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from int primitive type to another data type like String, boolean and char etc
Data Conversion from String to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from String primitive type to another data type like int, boolean and char etc
Data Conversion from short to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from short primitive type to another data type like String, boolean and char etc
Data Conversion from byte to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from byte primitive type to another data type like String, boolean and char etc
Data Conversion from float to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from float primitive type to another data type like String, boolean and char etc

Ads