Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7865205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:01:00+00:00 2026-06-03T00:01:00+00:00

I have two drop down list in my webpage and one is dependent on

  • 0

I have two drop down list in my webpage and one is dependent on the other. The Ajax code i am using is working fine in Chrome, Mozilla but not in IE (i am using IE9). Can someone please help me in getting this corrected.

This is the Ajax code-

 <script language="javascript" type="text/javascript">  
  var xmlHttp  
  var xmlHttp

  function showSubCategory(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="jsp/subcategory.jsp";
      url +="?count=" +str;
      xmlHttp.onreadystatechange = stateChange1;
      xmlHttp.open("GET", url, true);
      xmlHttp.send(null);
      }

      function stateChange1(){   
      if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){   
      document.getElementById("subcat").innerHTML=xmlHttp.responseText   
      }   
      } 

This the main jsp page where the drop down lists are.–

 <table>
     <tr>
<td align="right" width="10%">Category </td>
<td>
   <select id='category' name="adv.categoryNo" onchange="showSubCategory(this.value)">  
       <option >Select the Category</option>  
     <%
Class.forName("com.mysql.jdbc.Driver").newInstance();  
Connection con1 = DriverManager.getConnection("jdbc:mysql://localhost:3306/db","user","pwd");  
Statement stmt1 = con1.createStatement();  
ResultSet rs1 = stmt1.executeQuery("Select * from categories");
while(rs1.next()){
    %>
    <option value="<%=rs1.getString(2)%>"><%=rs1.getString(2)%></option>  
    <%
}
    %>
    </select>                                  
     </td>
    </tr>

   Second drop down list 


    <tr>
      <td align="right" width="10%">Subcategory <span class="mandatory">*</span>: </td>
       <td>
         <div id='subcategory'>  
         <select id='subcat'  name='subcategory'>  
         <option >Select the Subcategory</option>  
         </select>  
         </div>
    </td>
    </tr>

Here is the subcategory jsp file which is called by Ajax.

<%@page import="java.sql.*"%>
 <%
  String category=request.getParameter("count");  
   String buffer="<select name='adv.subCategoryNo'><option >Select the Subcategory</option>";  
 try{
  Class.forName("com.mysql.jdbc.Driver").newInstance();  
  Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db","user","pwd");  
  Statement stmt = con.createStatement();  
  ResultSet rs = stmt.executeQuery("Select * from subcategories where     categoryName='"+category+"' ");  
   while(rs.next()){
   buffer=buffer+"<option value='"+rs.getString(3)+"'>"+rs.getString(3)+"</option>";  
   }  
    buffer=buffer+"</select>";  
    response.getWriter().println(buffer); 
    }
   catch(Exception e){
    System.out.println(e);
    }
   %>

Strange thing is if i change the getElementById param in the following function of the Ajax code from “subcat” to “subcategory” which is the div id covering the second drop down list, it works fine in IE and other browsers.

function stateChange1(){   
      if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){   
      document.getElementById("subcat").innerHTML=xmlHttp.responseText   
      } 

If i follow the above approach i am not able to do any javascript form validation for that Subcategory select box using the following JS code.

 function madeSelectionCity(){
  var subcat = document.getElementById('subcat');
if(subcat.value == "Select the City name"){
    alert("Please select a subcategory first");
    subcat.focus();
    return false;
}else{
    return true;
}
 }

Hope i am clear in my question. Please let me know if any more explanation is required. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:01:02+00:00Added an answer on June 3, 2026 at 12:01 am

    Change the below line of code( in subcategory.jsp called by ajax code)

     String buffer="<select name='adv.subCategoryNo'><option >Select the Subcategory</option>";  
    

    to

     String buffer="<select id='subcat' name='adv.subCategoryNo'><option >Select the Subcategory</option>";  
    

    and also add this line of code ( in subcategory.jsp called by ajax code)

    response.setContentType("text/html");
    

    on the webpage(main page) , the html should be

     <div id='subcategory'>
     </div>
    

    and ajax(main page) code should be

    function stateChange1(){   
          if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){   
          document.getElementById("subcategory").innerHTML=xmlHttp.responseText   
          } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two dropdown list. first drop down:1 enter code here <form:select path=custName id=custName>
So I have two filtering objects. One is a drop down list, which chooses
I have a drop down list with two values (for now..) with other elements
I have two separate fields with a drop-down list, one is for User and
I have custom control with two textboxes and one drop down list. I want
I have two drop down list on a page. The first one list projects
lets say i have two drop down list and one button on my search
There will be two drop down lists, First have the list of mobile vendor,
I have a drop down list and some styles applied to it from two
I have two Drop Down Lists, the second ones are based off which one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.