Home Answers Viewqa Ajax Dynamic select box

 
 


Ragavendran
Dynamic select box
1 Answer(s)      3 years and 6 months ago
Posted in : Ajax

View Answers

December 18, 2009 at 12:25 PM


Hi Friend,

We have used the tables country(country_id(Number),countryname(Text)) and city(cityid(Number),country_id(Text),cityname(Text))

Try the following code:

<%@ page language="java" %>
<%@ page import="java.sql.*" %>

<%!
Connection conn = null;
ResultSet rs =null;
Statement st=null;
String query="";
int cid;

%>

<%
if(request.getParameter("cid")!=null){
cid=Integer.parseInt(request.getParameter("cid"));
}else {
cid=0;
}
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:access","","");
st = conn.createStatement();
rs = st.executeQuery("select * from country");
%>
<html>
<head>
<script type="text/javascript">

function selectCity(){
var cid=document.getElementById("country").selectedIndex;
window.location.replace("http://localhost:8080/examples/jsp/countrycombo.jsp?cid="+cid);
}
</script>
</head>
<body>
<select id="country" onchange="selectCity(this)">
<option value="0">--Please Select--</option>
<% while(rs.next()){ %>
<option value='<%=rs.getInt("country_id")%>'><%=rs.getString("countryname")%></option>
<%}%>
</select>
<%
rs = st.executeQuery("select * from city where country_id='"+cid+"'");
%>
<select>
<% while(rs.next()){ %>
<option value='<%=rs.getInt("country_id")%>'><%=rs.getString("cityname")%></option>
<%}%>
</select>
</body>
</html>

Thanks









Related Pages:
dynamic select box
dynamic select box  hello friends i created a form and details of city & locations have to be come from database. if city hyderabad chosen then locations of hyderabad only appear in location selectbox.plz send code it is more
Dynamic select box - Ajax
Dynamic select box  Hi, I Have almost completed the task... in the other select box automatically.. The city details must be extracted from... select boxes in my page.. One is "Select a Country" and other one is "Select
dynamic select box
dynamic select box  thank u my dear friend.but i have a code like...> <select name="city"> <option>city</option>...) die("access failed"); $select=mysql_select_db("vtigercrm530"); if(!$select
Dynamic check box problem
Dynamic check box problem  In my project i have used a dynamic table, in the each row of that table there is one check box [that i have created dynamically]. Now my problem is that i can't access those values from that dynamic
JavaScript Dynamic Combo Box
JavaScript Dynamic Combo Box Here we are going to create dynamic combo box... in respective arrays. As the user selects a country from the first combo box, the cities...(); arr[0] = new Array("-select-"); arr[1] = new Array("
dynamic drop down list box - Java Beginners
dynamic drop down list box  hi all , I want to dynamically populate a drop down box from an sql query in a servlet program, using only html... Rajanikant  Hi friend, dynamic bombobox in servlet
select box and text box validations
select box and text box validations  hi, any one please tell me how to set validations for select box and text boxes using bean classes? thank you   Please visit the following link: http://www.roseindia.net/jsp/user
Dynamic loading of Combo box list using servlet - JSP-Servlet
Dynamic loading of Combo box list using servlet  I have the category... database dynamically, when I select the category? Plz help me.  Hi friend I give theortical descrption read it! Select a value from drop dwon box
Multiple select box
Multiple select box  Hi, I need help in code for multiple select box. The multiple select box should be populated with the db values.The selection done in the multiple select box is to be moved to the text area provided a add
Drag a Text Box into dynamic positions
Drag a Text Box into dynamic positions  Plz can anyone tell how can i drag a text box using mouse or arrow keys... Im doing a accounts projects and i need this feature for cheque configuration
dynamic display - JSP-Servlet
dynamic display  hi, i want to display dynamic values in drop drown box in a jsp page.these values are in the form of arraylist's object which... = "select name from data"; Statement s = connection.createStatement
java-select dynamic files. - Java Beginners
java-select dynamic files.  My java program is processed files. Now i have set inputfile is default location. i want to change input file location in run time. How to insert new files in run time. I need to take system file
how to operate on select box using ajax in struts2?
how to operate on select box using ajax in struts2?  I am doing a project on struts2 in which i have a jsp page which has two select boxes like Now i want to use ajax so that when i select a district value
how to operate on select box using ajax in struts2?
how to operate on select box using ajax in struts2?  I am doing a project on struts2 in which i have a jsp page which has two select boxes like <... it by assigning to the block list select box. so please help me..its urgent
display from select box - JSP-Servlet
display from select box  I am doing a jsp project. In this jsp project i have to show the photos in one cell depending on the selection from other selection box which is in the same page. The photos are stored
Dynamic Dropdown Menu
Dynamic Dropdown Menu       Put records from your database in a drop down menu/list box. You can apply it as a navigator list box. Good for saving your webpage areas or you have many links you
dynamic form
dynamic form  I need to make a dynamic form using php, for example, i will need a list of items which when we select one option another list... dependent dropdown lists using Ajax. when the user select country name from the first
Dynamic form
Dynamic form  I need to make a dynamic form using jsp for example, i will need a list of items which when we select one option another list... list consisting of country names. When the user select any country name
dynamic generation of html:select tag from textbox value
dynamic generation of html:select tag from textbox value  Hi, I am a newbie to java and struts. In my application, I have a requirement like when i give some input in a textbox and click on a add link. It should be added
dynamic generation of html:select tag from textbox value
dynamic generation of html:select tag from textbox value  Hi, I am a newbie to java and struts. In my application, I have a requirement like when i give some input in a textbox and click on a add link. It should be added
dynamic query
dynamic query  DECLARE QUERY VARCHAR2(32767); FIN_QUERY VARCHAR2(32767); CURSOR C IS (select distinct PORTFOLIO from MPE_TEST1); CURSOR C2 IS SELECT DISTINCT PORTFOLIO_LEVEL, PORTFOLIO FROM MPE_TEST1 ORDER
how to display(update) current date and month in select box on selecting the year.
how to display(update) current date and month in select box on selecting the year.  how to display(update) current date and month in select box on selecting the year
How to implement ajax in struts2 to operate on select box in jsp
How to implement ajax in struts2 to operate on select box in jsp  I am doing a project on struts2 in which i have a jsp page which has 2 select boxes... by assigning to block list select box... plz help me .. its urgent .. thanx in advance
Use of Select Box to show the data from database
Use of Select Box to show the data from database       Example program using Select Box to show retrieved data from database This example will describe you the use of Select Box in a JSP
How to write a select box and id should be stored in database?
How to write a select box and id should be stored in database?  Hi, How to write a select box and select the name(devi) regarding name id(like 60...); JLabel lab=new JLabel("Select Name:"); final JComboBox combo
Passing Multi select list box values using ajax to get values to dependent list box
Passing Multi select list box values using ajax to get values to dependent list box  Hi, I have a jsp page which has 3 dependent list boxes... the dependent values to the immediate next list box. Please help me
jQuery 'select' form event
input box. In this Example, two input text box are given , when we select...; Click and drag the mouse to select text in the input box. </p>...jQuery 'select' form event In this tutorial, we will discuss about
combo box
combo box  Hi, [_|] dropdown box... a screen like this using jsp-servlet(or DAO,DTO),in that drop down box i should get... to that user in left list.when we select module from left list and click INCLUDE button
dynamic drop down list
dynamic drop down list  I want to create 2 drop down list, where it takes value from database and the two list are dependent..means if I select a particular value from one the other list is developed accordingly..depending
dialog box
numeric choice to select answers  hello. write an application that displays a series of at least four interview questions and each question should... of the interview, use a dialog box to ask whether the user wants to - enter another set
Dynamic link in JSP
Dynamic link in JSP  Hii everyone...I have stuck from last 2 days... to choose some checkboxes n save it in collection. So, for every link, we can select... stuck with this LINK ...How to generate this dynamic link n all? I have tried
action for dropdown box - Java Server Faces Questions
for populating a list box from a drop-down selection? What I want to do is give the user a dynamic drop-down list. (I already have this) And when they make a selection from the drop-down list, the list box beside it gets populated
dynamic drop down
dynamic drop down   I have created 2 drop downs in jsp.1 for department and other for its related designation.that means if I select a department...; <select onchange="showDesig(this.value)"> <option value="none
dynamic delete and insertion in tables
dynamic delete and insertion in tables  hey... i have a problem..I am...); if(login_name.equals("mehak")) { cmd="select * from problem where...")) { cmd="select * from problem where area='Gate Pass
dynamic delete and insertion in tables
dynamic delete and insertion in tables  hey... i have a problem..I am...); if(login_name.equals("mehak")) { cmd="select * from problem where...")) { cmd="select * from problem where area='Gate Pass
second selectbox of dynamic
;/td><td colspan=1> <select name="city"> <option>..."); if(!$connect) die("access failed"); $select=mysql_select_db("vtigercrm530"); if(!$select) die("select failed"); echo "selected vtigercrm530"; $query
Not Able to select an Item in Spark Combo Box control (Adobe Flex Object) using QTP
Not Able to select an Item in Spark Combo Box control (Adobe Flex Object) using... Flex controls. But i am not able to select any item from Spark Combo Box. I tied using .Open (Its not opening the drop down list) , also i tried using Select
select option value
select option value  if i select a value of any drop down then that value should be used in a select query of the next dropdown in jsp????   Here is an example of dependent dropdown box in JSP. The values come from
select option value
select option value  if i select a value of any drop down then that value should be used in a select query of the next dropdown in jsp on same page????   Here is an example of dependent dropdown box in JSP. The values
add text box and select list dynamically and get its value to store it into database using jsp request parameter
add text box and select list dynamically and get its value to store it into database using jsp request parameter  its very helpful when you have only... added select box also into next jsp page plz reply me as early as posssible
nested select tag
nested select tag  My requirement is as follows suppose combobox to select country whenever i select a country it will show corresponding states in another combo box.   JSP Code 1)country.jsp: <%@page import
i want to select a multiple value of check box by using onclick or onchange event without using from submission
i want to select a multiple value of check box by using onclick or onchange event without using from submission   i have 4 check box name 1)profile... the result is ok but after getting value of first box now i want a result of second box
how to select second combobox value .
how to select second combobox value .  I requirement is , i have two combo box, i am selected first combo box value then automatically second combo box value show ,But this both combo box value i retrieves in database. please
How to add dynamic table in java
How to add dynamic table in java  How to add dynamic table in java   import java.awt.*; import java.sql.*; import java.util.*; import...("jdbc:odbc:access"); String sql = "Select * from data"; Statement stmt
Bulk insert and dynamic schema loading
Bulk insert and dynamic schema loading  Hi All, I am new to H2 database and java. I have started working on these from past 1 month. I needs some... reporting engine. Query is split and only the select with where is run
select one item name throug combo box than other combobox show item price
select one item name throug combo box than other combobox show item price  i have one table in database item master..if i select one item name through combo box than other combobox show item price only select item name... how i
Dependant & dynamic drop down list
Dependant & dynamic drop down list  I don't know this should be in this or AJAX forum. I have one dynamic drop down list from data base (working fine) Use can select random entries from this table & hit "RETRIEVE
check box in jsp
check box in jsp  hey guys i am working on a web based project using jsp. In my project 1 am having 9 check boxes in 3 rows in the same form. I want to select 1 check box from each row and also i want to avoid many check box
JCombo Box problem
combo box display number of week in a selected month for the year. I am select year, month and the third combo box display the number of week. If i select any one...JCombo Box problem  I have three combo boxes First combo box display
List Box - JSP-Servlet
list box.on selecting one value in list box,i will retrieve values from database and store into another list box in same page using javascript :location.my problem is in first list box,value which i selected to get values is not displaying