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 7511611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:36:09+00:00 2026-05-29T23:36:09+00:00

I have two dropdowns in html. Both dropdowns are getting data mysql first dropdown

  • 0

I have two dropdowns in html. Both dropdowns are getting data mysql first dropdown is “hostgroup” having value like “windows,linux” and second dropdown is “host” having value like”office,home,sidearea,localhost”

Basically I want to do it so when I select “linux” is hostgroup combobox it will filter “host” dropdown box and show only localhost in “host” dropdown and when I select “windows” in hostgroup dropdown it will filter it and remove localhost from host dropdown

My code for filling dropdown in html is,

 html.append("<select id='hosts' name='hosts' style='width: 180px' onchange=\"document.forms['form1'].submit();\">>");
        //if(rs != null)
        //{
       while(rshostgroup.next())
           {
                  html.append("<option value='"+rshostgroup.getString(2)+"'>"+rshostgroup.getString(1)+"</option>");
                //html.append("<option value='web'>web</option>");
            }
        //}

        html.append("<select>");
        html.append("</td>");
        html.append("</tr>"); 

         html.append("<tr>");
        html.append("<td>"); 
        html.append("Host");        
        html.append("</td>");  
        html.append("<td>"); 
        html.append("<select id='hosts' name='hosts' style='width: 180px' onchange=\"document.forms['form1'].submit();\">>");
        //if(rs != null)
        //{
       while(rshost.next())
           {
                  html.append("<option value='"+rshost.getString(2)+"'>"+rshost.getString(1)+"</option>");
                //html.append("<option value='web'>web</option>");
            }
        //}

        html.append("<select>");

Please dont get confuse that what html.append is and what is option value comming from

Actually I am using string builder appending my string builder html in .java(class) file and calling class html appended method in jsp. It is working fine and the option value of drop down is filling from ResultSet rs and rshost having data from mysql.

  • 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-05-29T23:36:10+00:00Added an answer on May 29, 2026 at 11:36 pm

    Firstly using java to build HTML element is a terribly bad idea.
    Use JSTL to loop through the dropdown options instead of using Java to spit out HTML code.
    Secondly the problem you mention has nothing to do with Java and everything to do with JavaScript.

    Well, not entirely true as you might have to make an AJAX request to server get values to populate your secondary dropdown box.

    What you need to do is attach a onChange listener for the primary dropdown so that when it changes your javascript code either makes a AJAX call to server to get values for your secondary dropdown box, or use hardcoded values held in some javascript variables.

    You will have to loop through the secondary dropdown to remove all previous values and add new dropdown options to it or alternately you can remove the secondary dropdown box entirely and recreate it with the new values based on the selection of the primary dropdown box.
    There’s already more than enough articles in the internet so use your fiend Google to find the ones that suits your needs closely.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two dropdowns. When a user selects a value from the first one
I have a dropdown. I need to bind with two field of datatable value
Can I refresh a HTML component in JSP? I have two dropdowns. On selection
I have a form on my page which contains two select dropdowns. The first
Form contains two dropdown lists created using code below. Both dropdown list elements have
Am I doing this correctly? I have two dropdowns. The first is populated on
I have two dropdowns. I want to populate the second dropdown on selection of
I have two dropdowns @using (Html.BeginForm()) { <fieldset> <legend></legend> <label>User details</label> <section> @Html.LabelFor(model =>
I have two dropdowns and I want the second dropdown to get populated on
I have a DropDown menu in an HTML form each with a specific value

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.