Home Answers Viewqa JSP-Servlet select option value

 
 


nishant nair
select option value
1 Answer(s)      a year ago
Posted in : JSP-Servlet

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????

View Answers

June 8, 2012 at 11:31 AM


Here is an example of dependent dropdown box in JSP. The values come from the database and stored into the first combobox. When the user selects the value from first combobox, the dependent values will get stored into second combo box through the MySQL database.

1)country.jsp:

<%@page import="java.sql.*"%>
 <html>
      <head>  
      <script language="javascript" type="text/javascript">  
      var xmlHttp  
      var xmlHttp
      function showState(str){
      if (typeof XMLHttpRequest != "undefined"){
      xmlHttp= new XMLHttpRequest();
      }
      else if (window.ActiveXObject){
      xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
      }
      if (xmlHttp==null){
      alert("Browser does not support XMLHTTP Request")
      return;
      } 
      var url="state.jsp";
      url +="?count=" +str;
      xmlHttp.onreadystatechange = stateChange;
      xmlHttp.open("GET", url, true);
      xmlHttp.send(null);
      }

      function stateChange(){   
      if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){   
      document.getElementById("state").innerHTML=xmlHttp.responseText   
      }   
      }
      </script>  
      </head>  
      <body>  
      <select name='country' onchange="showState(this.value)">  
       <option value="none">Select</option>  
    <%
 Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
 Statement stmt = con.createStatement();  
 ResultSet rs = stmt.executeQuery("Select * from country");
 while(rs.next()){
     %>
      <option value="<%=rs.getString(1)%>"><%=rs.getString(2)%></option>  
      <%
 }
     %>
      </select>  
      <br>  
      <div id='state'>  
      <select name='state' >  
      <option value='-1'></option>  
      </select>  
      </div>  
      </body> 
      </html>

2)state.jsp:

 <%@page import="java.sql.*"%>
<%
String country=request.getParameter("count");  
 String buffer="<select name='state' ><option value='-1'>Select</option>";  
 try{
 Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
 Statement stmt = con.createStatement();  
 ResultSet rs = stmt.executeQuery("Select * from state where countryid='"+country+"' ");  
   while(rs.next()){
   buffer=buffer+"<option value='"+rs.getString(1)+"'>"+rs.getString(3)+"</option>";  
   }  
 buffer=buffer+"</select>";  
 response.getWriter().println(buffer); 
 }
 catch(Exception e){
     System.out.println(e);
 }

 %>

For the above code, we have created two database tables:

CREATE TABLE `country` (                                 
           `countryid` bigint(255) NOT NULL auto_increment,       
           `countryname` varchar(255) default NULL,               
           PRIMARY KEY  (`countryid`));                             

CREATE TABLE `state` (                                   
          `stateid` bigint(255) NOT NULL auto_increment,         
          `countryid` int(255) default NULL,                     
          `state` varchar(255) default NULL,                     
          PRIMARY KEY  (`stateid`));









Related Pages:
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... buffer="<select name='state' ><option value='-1'>Select</option>
select option value
select option value  if i select a value of any drop down...("Select * from country"); while(rs.next()){ %> <option value... id='state'> <select name='state' > <option value='-1
jsp drop down-- select Option
;nbsp;</td> <select name="sel"><option value=""><---Select..."); String buffer="<select name='state'><option value='-1'>Select<... = results.getString(2); String id = results.getString(1); %><option value="<%= name %>
Option Box Value - Java Beginners
Option Box Value  Hi Friends, I have one option box which is division, division have dynamically data,if user select any division then his option box is populated (work schedule,Peronal Area,personal sub area,business
select option with text facility - JSP-Servlet
select option with text facility  Hello. My doubt is regarding how to provide facility to add text in a drop down box ie(select tag in html )in a jsp... the select in html and if the user wants also to directly type the option instead
validate select option jquery
validate select option jquery  How to Validate select option in JQuery
select option - JDBC
select option  how to dynamically generate the select option values from database
Jsp Option Value
;option value="">--select--</option> <option value...;/td> <select name="sel"><option value=""><---Select---><... Jsp Option Value   
How to add another option to the select tag using struts2 tag - Struts
How to add another option to the select tag using struts2 tag  Hi, How to add another option to select tag using tag. My scenario... + one additional value in drop down or else normal user to view only drop down
Add values of drop down menu( select option) to mysql table
Add values of drop down menu( select option) to mysql table   Here...['valveId'].'<td>'; echo '<select name="onoff">'; echo '<option value="ON">ON'; echo '</option>'; echo '<option
how to display textbox value based on selected option value?
how to display textbox value based on selected option value?  Hi,I have some problem. I use jsp and ajax. first select: 1 second select:2 based on first value I finished above code. ID: xx Name:xx xx is baesd on second
Select from select list + display
"); while(rs.next()){ %> <option value="<...Select from select list + display  i have a select list containing... select EmpCode from the select list, the corresponding EmpName and DeptName should
Option onclick am not getting the value ..
Option onclick am not getting the value ..    function get_val( tot_val ) { document.getElementById('TextBox1').value = tot_val; } <..._val( tot_val ) { document.getElementById('TextBox1').value = tot_val
Input type select
: <select name="country" size="2"> <option name="Australia" value...="Belgium" value="Belgium">Belgium</option> <option name="Germany" value="Germany">Germany</option> <option name="India" value="India" >
nested select tag
("count"); String buffer="<select name='state'><option value='-1'>...' onchange="showState(this.value)"> <option value="none">Select<...; <option value="<%=rs.getString(1)%>"><%=rs.getString(2)%><
Select DropDown Default
; <option value="">-=Show All=-</option>...; <option value="<%=rs.getString(1)%>"><...Select DropDown Default  Hi there, i have a program in JSP where i
jQuery change event with multiple select option
jQuery change event with multiple select option In this tutorial , we...; it also display the selected option. In the below example a multiple select list is given, when we select any option/options a change event is triggered
Multiple select box
"); while(rs.next()){ %> <option value="<%=rs.getString("name")%>">...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
dynamic select box
dynamic select box  thank u my dear friend.but i have a code like...; <input type="hidden" value="Leads" name="moduleName" /> <table>...;/label></td> <td><input type="text" name="lastname" value
JavaScript getElementById select
to perform any operation with the selected value as a option. We will be describing you... as document.getElementById().value. Similarly we have shown the selected option...; onChange="selectTypeOption();"> <option value="
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
For every option selected from a dropdown a new textbox opens
;select name="sel" onchange="generateTextbox();"> <option value="C/C++">C/C++</option> <option value="Java">Java</option> <option... have a dropdown with four options, each time I select an option a new text box
Javascript get Date And Selected Option Text
for taking date and select and option tags for providing the dropdown list...Javascript get Date And Selected Option Text In this tutorial we will learn... to get the selected option text and displayed in Javascript. This tutorial
how to get the value of a label field of option tag in javascript?
how to get the value of a label field of option tag in javascript?  example <select> <option label="2" value="A">A</option> <option label="5" value="B">B</option> <
JavaScript validate select tag
="n1"> <option value="Select">Select</option> <option value="10">10</option> <option value="20">20</option> <option value="30">30</option>
how to calculate the price on the option box
how to calculate the price on the option box  How i calculate the value when i using a option box with 2 option..first option i used for product name... to calculate this value
select query
select query  how to retrieve a single image from mysql table using $row[] value
ftech different value corresponding different value
ftech different value corresponding different value  in my dropdown two options are their and i want when i select any option the corresponding value... there are two optiond like delhi and mumbai so if a person select delhi then entry
help to select a value from the dropdown list
help to select a value from the dropdown list  I have a html file...()); } %> Please can someone help me on how to select a value...("$('#suggestions').hide();", 200); } $('#inputString').select(function
Column select
Column select   How i fetch Experience wise resume?   ... or no. Then using the query select * from resumes where experience='yes', fetch all the data...("jdbc:mysql://localhost:3306/test", "root", "root"); String query = "select * from
Select Tag&lt;html:select&gt;:
to any arbitrary value, the rendered select element will support multiple... browser displays the following page. Don't select the option... selecting option... Now select any option
JavaScript remove method
. <select id="myselect"> <option value="1">Vineet</option> <option value="2">Sandeep</option> <option value="3">Vinod</option> <option
combo box value
' onchange="showState(this.value)"> <option value="none">..."); while(rs.next()){ %> <option value="<...; <option value='-1'></option> </select>
combo box value
"); String buffer="<select name='state' ><option value='-1'>Select<...' onchange="showState(this.value)"> <option value="none">...; <option value="<%=rs.getString(1)%>"><%=rs.getString(2)%><
jQuery image replacement by click or select
;target"> <option value="" selected="selected">Select... by button click or by selecting an option of select drop down box without refreshing... () { $("select option:selected").each(function () { $("#img").attr
. Display JavaScript dropdown selected value
="dropdown" onchange="selectDropdown()"> <option value="India" >India</option> <option value="US" >US</option> <option value="UK" >UK</option> <option value="Japan" >Japan</option> <option
JavaScript add method
: it is the option value which is to be added into the select tag's option list... value to be added and it is also required while adding some option to the select.... Here in this example we have added an option to the select tag by using the add
Table's row elimination based on option choosen
Table's row elimination based on option choosen  I have a drop down with yes and no option.if i select yes in a table 2 new rows are shown and if i select no another question in row appears but the space occupied by the question
Multiple select dropdown with Ajax
(); %> <option value="<%=category.getCategoryId()%>"...()){ Category category=iterator.next(); %> <option value="<...=iterator.next(); %> <option value="<%=category.getCategoryId
html:select in struts - Struts
html select in struts  What is the HTML select in struts default value
How to give value for select in HTML dynamically using javascript
How to give value for select in HTML dynamically using javascript  hi. Consider the situation i am having 2 select options called degree and department. if i select a degree the departments corresponding to that degree only
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database.  Hii Sir, Lots of thnx to ur reply .I went through both... of selecting value from autocomplete textbox using jquery in jsp from mysql database
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database.  Sir, Lots of thnx to ur reply .I went through both the tutorials but was unable to find out exact way to fullfill the solution of selecting value from
select date in desired format
select date in desired format  how to select date from the database in DD/MM/YYYY format, because if i am trying select data from the database i am getting value in yyyy/mm/dd and time format like below "2012-05-07 00:00:00.0
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
Select Color
Select Color      ... firstly we need to make one html page. Inside the page we will have one select option in which we will have our colors. We will also have a submit, clicking
HTML5 option tag, Example of &lt;option&gt;tag.
label for option. value string Initial value of option...HTML5 option tag, Example of <option> tag. Here, you will see the use... option for drop-down list or selection list. Every thing presents in option tag
where clause in select statement
where clause in select statement  In Mysql,I write the following query: select * from emp where designation = "MANAGER" But the actual value in the table is "manager" Will the above query retrieve any records? According to me
Help with SELECT/JOIN statement
Help with SELECT/JOIN statement  I have two tables (t1 and t2... a select statement that will return me all rows of t1 but, when t1.id = t2.id, I... | value ------------------- 1 | joe | 3 2 | bob | 5 3 | ted | 7 t2