Question: combo box code problem

Ads

 
 
 

Share on Google+Share on Google+

mala patidar
combo box code problem
1 Answer(s)      5 years and 2 months ago
Posted in : Java Beginners

in this my problem related to :

when i select state MP then i wil open the its corresponding city but in database it only stores the option value no like MP at option value 10 then it will stores the 10 for city becuz it wil call the correspndng array[10] in MS Access database

<html>
<head>
<script language="javascript">
var arr = new Array();
arr[0] = new Array("-select-");
arr[1] = new Array("Adilabad","Anantapur","Chittoor","Cuddapah","East Godavari","Guntur","Hyderabad","Karimnagar","Khammam","Krishna","Mahbubnagar","Medak","Nalgonda","Nellore","Nizamabad","Prakasam","Rangareddy","Secundrabad","Srikakulam","Tirupati","Vijayawada","Visakhapatnam","Vizianagaram","Warangal","West Godavari");
arr[2] = new Array("Anjaw","Changlang","East Kameng","East Siang","Kurung Kumey","Lohit","Lower Dibang Valley","Lower Subansiri","Papum Pare","Tawang","Tirap","    Upper Dibang Valley","Upper Siang","Upper Subansiri","West Kameng","West Siang");
arr[3] = new Array("Barpeta","Bongaigaon","Cachar","Darrang","Dhemaji","Dhubri","Dibrugarh","Goalpara","Golaghat","Guwahati(Dispur)","Hailakandi","Jorhat","Kamrup","Karbi Anglong","Karimganj","Kokrajhar","Lakhimpur","Marigaon","Nagaon","Nalbari","North Cachar Hills","Sivasagar","Sonitpur","Tinsukia","Udalguri");
arr[4] = new Array("Araria","Arwal","Aurangabad","Banka","Begusarai","Bhagalpur","Bhojpur ( Arrah )","Buxar","Darbhanga","East Champaran","Gaya","Gopalganj","Jamui","Jehanabad","Kaimur (Bhabua)","Katihar","Khagaria","Kishanganj","Lakhisarai","Madhepura","Madhubani","Munger","Muzaffarpur","Nalanda","Nawada","Patna","Purnia","Rohtas","Saharsa","Samastipur","Saran","Sheikhpura","Sheohar","Sitamarhi","Siwan","Supaul","Vaishali","West Champaran");
arr[5] = new Array("chandigarh");

function change(combo1){
var comboValue = combo1.value;
document.forms["form1"].elements["combo2"].options.length=0;
for (var i=0;i<arr[comboValue].length;i++){
var option = document.createElement("option");
option.setAttribute('value',i+1);
option.innerHTML = arr[comboValue][i];
document.forms["form1"].elements["combo2"].appendChild(option);
}
}


  </script>


</head>

<body>



     <form name=form1  action="reg.jsp"  onsubmit="return validateForm()" method="post" >

<table width="425"  border="0" cellspacing="0" cellpadding="3">


    <tr><td width="5px" height=" 26px"></td><td height="26px" width="326px">
    <span id="lblState">State</span></td>
    <td width=" 193px" height=" 26px">
    <select name="ddlstState" onchange="javascript:setTimeout('__doPostBack(\'ddlstState\',\'\')', 0)" id="ddlstState" class="txtBox" width="119px">
    <option selected=3D"selected" value="0">-State-</option>

    <option value="Andhra Pradesh">Andhra Pradesh</option>

    <option value="Arunachal Pradesh">Arunachal Pradesh</option>
    <option value="Assam">Assam</option>
    <option value="Bihar">Bihar</option>
    <option value="Chandigarh">Chandigarh</option>


</select></td>
       <select name="combo2" >
</select>
    <td width="200px" height="26px"></td></tr>
    <tr><td width="5px"></td><td width=" 326px">
    <span id="lblCity">City/District </span></td>
    <td width=" 193px">
    <select name="ddlstCity" id="ddlstCity" class="txtBox" width="119px">
    <option value="0">-City/District-</option>

</select></td>
    <td width="200px"></td></tr>


<td width=" 193px">

      <input type="submit" name="submit" id="submit" value="Submit" />
      <input type="submit" name="Cancel" id="Cancel" value="Cancel" />
    </td>

    </tr>
</form>



</body>
</html>
Ads
View Answers

March 22, 2012 at 11:24 AM


1)country.jsp:

<[email protected] 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:

<[email protected] 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`));

Ads









Related Tutorials/Questions & Answers:
combo box code problem
combo box code problem  in this my problem related to : when i select state MP then i wil open the its corresponding city but in database it only stores the option value no like MP at option value 10 then it will stores the 10
Problem With Combo Box Editable Property
Problem With Combo Box Editable Property  Hi I am new To Flex i had set Combo Box Editable Property as true. But I didn't get the property filtering in the combo box like when you enter text "S" in the combo box then the names
Advertisements
Sub combo box problem - Development process
Sub combo box problem  Hi, In this code Sub-Combo box is not working. plz solve the problem Search Page var arr = new Array(); arr["Select"] = new Array("-select-"); arr["Dkn/Tmz"] = new Array
combo box
combo box  Hi, [_|] dropdown box [ ] [INCLUDE... a screen like this using jsp-servlet(or DAO,DTO),in that drop down box i should get
Code to store sub combo box value - Development process
Code to store sub combo box value  Hi Deepak, In the following code i want to store subcombo box value instead of number. Already "Dkn/Tmz" ,"kungumam... etc are storing but i want to store "Circulation,marketing
populate Combo Box dynamically
populate Combo Box dynamically  Hi, How to populate the Combo Box dynamically using Flex with Jsp's
combo box - JSP-Servlet
combo box  how to get a combo box in jsp page which allows editing as well as list box
assigning arraylist to combo box
assigning arraylist to combo box  Hi I am busy coding the Airline Reservation program, i have an arraylist of locations which i want to assing to the combo box. please help
date in combo box
date in combo box  strong texthello, how can i desplay the current year and next year in combo box???!!! it must be uppdate atumaticaly every year>>>
combo box connection
combo box connection  how to provide connection between three combo boxes,if my 1st combo box is course and 2nd combo box is semester and 3rd combo... combo boxes.   Here is Java swing code: import java.sql.*; import
populating the combo box - Struts
populating the combo box  Hi I am having problem populating the combo box with a table in MS SQL Server 2005 Management Studio Express. Belo...; } ========================================================================== My problem is populating the combobox table
Combo Box - Struts
Combo Box  I hava acombo box cnnected to my database via html collections. When selecting an option, i want to display specific parts (sectons) on my web page....am trying to use logic:present and logic:empty but its not working
combo box value
combo box value   i want to populate one combo box value based on another combo box value using ajax   1)country.jsp: <[email protected].. e){ System.out.println(e); } %> For the above code
Helps with combo box and frame
Helps with combo box and frame  Hi i have a combobox and when i click... on the second window and click confirm i would have the information on the combo box. i don't really know how to doing it.   Sorry i forget to put my code i
Combo box value Error - WebSevices
Combo box value Error   if($_SERVER['REQUEST_METHOD'] == 'POST... the correct code for this.   Hi friend, Please give the full details and source code to solve the problem. http://www.roseindia.net
loading value into combo box by selecting value from other combo box - JSP-Servlet
loading value into combo box by selecting value from other combo box  ... and code; each district table contain constituency and code. MY problem is that as i select state from state_combo_box,then the next combo box is dynamically
combo box value
combo box value   i want to populate one combo box value based on another combo box value using ajax   1)country.jsp: <[email protected] import="java.sql.*"%> <html> <head> <script language
combo box - JSP-Servlet
combo box  I am using a JSP form in which a combobox is given and I want to populate data in it from database and on the basis of yhe selected item... table country(country_id,country) in database and try the following code
java combo box
java combo box  how to display messagedialogbox when the combobox is null, Thanks in advance
Loading combo box from oracle
Loading combo box from oracle  how can i load values into a combobox from oracle database when a value is selected in another combo box
Dojo Combo Box
Dojo Combo Box          In this section, you will learn what is combo box and how to create a combo box in dojo. For creating the Combo box  you need "
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 of that country, get populated into the second combo. Here is the code
How to create Combo Box in SWT
How to create Combo Box in SWT       This section illustrates you how to create a combo box... an action on the second combo box. The items tea , coffee and cold drink
how to create a combo box in html
how to create a combo box in html  <tr> <td>Number<span class=mandatory>*</span></td> <td> <select name="number" id="course" style="width:158px;"> <option value="none">----Select
Combo Box operation in Java Swing
); The above code has been used to create a combo box in this program. The JComboBox... Combo Box operation in Java Swing   ... the Combo Box component, you will learn how to add items to the combo box
Retrieving Data from Database to fill Combo Box
Page with a combo box and a label. I have a database that has two fields id and an image. Now I want to fill the combo box with image and on selecting a particular image in combo box it should be displayed on the label. My combo box is only
how to get selected name from combo box
how to get selected name from combo box   i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz
how to get selected name from combo box
how to get selected name from combo box   i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz
how to get selected name from combo box
how to get selected name from combo box  i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz answer
how to get selected name from combo box
how to get selected name from combo box  i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz answer
how to get selected name from combo box
how to get selected name from combo box  i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz answer
Tutorials   
Java Spring Hibernate Struts Training Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java Java Example Codes and Tutorials in 2017 How do I read a large file quickly in Java? Is learning Java worthwhile? How to create first Java Program? Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include?

Ads

 
Advertisement null

Ads