1 Replies - 6277 Views - Last Post: 12 June 2011 - 04:10 PM

#1 shrutibansal1807  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-June 11

Storing the selected values from combo box.

Posted 09 June 2011 - 01:42 AM

I have 2 dropdown menus which i have connected with each other. When I select a value in first drop down menu... the corresponding values to it are displayed in 2nd drop down menu. How can i Store the values in a database which i select From the 1st and the 2nd drop down menu.

I am writing the code how i have linked the 2 dropdown menus.

<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%>
<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="dep_name.jsp";
         url +="?count=" +str;
          xmlHttp.onreadystatechange = stateChange;
             xmlHttp.open("GET", url, true);
         xmlHttp.send(null);      }
         function stateChange(){
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){

         <%--function selValue()
         var mytext = document.form.sel.options[document.form.sel.selectedIndex].text;

    <select name="officename" onchange="showState(this.value);">
        <%--<option value="select">Select</option>--%>
        Connection c = DriverManager.getConnection("jdbc:odbc:jsw");
Statement stt=c.createStatement();
ResultSet rss=stt.executeQuery("Select * from office_name");
 while(rss.next()){  %>
<option value="<%=rss.getInt("officenameid")%>"><%=rss.getString("officename")%></option>  <% } %>
    </select> <br> <%--<div id='dep_name'>
        <select name='dep_name' >
            <option value='-1'></option>


<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%>
<%String office_name=request.getParameter("count");
int id=Integer.parseInt(office_name);
String buffer="<select name='dep_name'>";
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:jsw");
 Statement stmt = con.createStatement();
 ResultSet rs = stmt.executeQuery("Select * from dep_name where officenameid="+id+" ");

    while(rs.next()){   buffer=buffer+"<option value='"+rs.getInt("depnameid")+"'>"+rs.getString("depname")+"</option>"; }
 response.getWriter().println(buffer);  }
catch(Exception e){     System.out.println(e); } %>

Is This A Good Question/Topic? 0
  • +

Replies To: Storing the selected values from combo box.

#2 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1012
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: Storing the selected values from combo box.

Posted 12 June 2011 - 04:10 PM

Is the problem with the ajax request, or the jsp file?
Also, please indent your code, it is almost impossible to read and debug, and makes it hard to help you :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1