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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:04:07+00:00 2026-06-10T03:04:07+00:00

I have two select dropdowns where the options of the 2nd select box needs

  • 0

I have two select dropdowns where the options of the 2nd select box needs to be changed according to the 1st select. The form is

<form action="" method="post" >
        <div style="padding-bottom:6px;">
            <select id="portfolios" name="portfolio" style="width: 200px; height:25px;">
                <option selected="selected" value="default">Select Portfolio</option>
                {% for portfolio in portfolios %}
                    <option get-groups="{{ path('v2_pm_patents_getgroups') }}" value={{ portfolio.id }}>{{ portfolio.portfolioName }}</option>
                {% endfor %}
            </select>
            <span>OR</span>
            <a class="modalbox1" href="#inline1">[Add New Portfolio]</a>
        </div>

        <div style="padding-bottom:6px; display:none;" id="groups">
            <select id="portfolio-groups" name="portfolio-groups" style="width:200px; height:25px;">
                <option selected="selected" value="default">Select Portfolio Group</option>
            </select>
            <span> OR</span>
            <a class="modalbox2" href="#inline2">[Add New Group]</a>
        </div>
</form> 

Initially the 2nd dropdown is hidden when I select an option from the 1st select it becomes visible.
The JQuery I wrote is

<script>
    $(document).ready(function(){
        $('#portfolios').change(function() {
            $('#groups').show();
            var id = $("#portfolios").val();
            var url = $('option:selected', this).attr("get-groups");
            var data = {PID:id};
            $.getJSON(url, data, function(result) {
                var options = $("#portfolio-groups");
                $.each(result, function(item) {
                    options.append($("<option />").val(item.id).text(item.name));
                });
            });
        });
    }); 
</script>

My Controller method which I call is

public function getgroupsAction(Request $request){
    if ($request->isXmlHttpRequest()) {

        $id = $request->get("PID");
        $em = $this->getDoctrine()->getEntityManager();
        $portfolio_groups = $em->getRepository('MunichInnovationGroupPatentBundle:PmPatentgroups')
        ->getpatentgroups($id);
        echo json_encode($portfolio_groups);
        return new Response();
    }
}

I get the correct groups from my query and in JSon Object. The Object in response looks like

[{"id":"09c0d4b2-ac25-11e1-96a5-9787dec335c2","name":"Group 2","description":"No Description Provided for this Group","order":500000,"is_deleted":false}] 

In my JQuery I append options to select box but the problem is it appends the options but with empty value atribute and no text. So neither the text nor the value attribute is visible just empty options are added.

What I am doing wrong? and How can I clear the select box before appending options?

Thanks in advance

  • 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-10T03:04:08+00:00Added an answer on June 10, 2026 at 3:04 am

    It looks like you are getting your JSON response wrapped inside an array. Try accessing your elements inside $.each like this item[0].name and item[0].id

    Then you’d need to account for getting multiple objects and loop over the item array

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

Sidebar

Related Questions

I have a form on my page which contains two select dropdowns. The first
I have two dropdowns Dropdown 1 <form:select path=StartTimings id=startTime onchange=javascript:changeTiming()> <form:option value=9:00 AM>9:00 AM</form:option>
<html> <head> <title>ADD URL Sources</title> </head> <body> <form action=Test1.jsp method=post> <br><br><select name=source onchange=> <option
i have two dropdown list. first drop down:1 enter code here <form:select path=custName id=custName>
I have two select fields in a form. Every time one of these select
I have three dropdowns First dropdown options are option1 option2 2nd and third dropdowns
if I have two dropdowns such as: <select> <option value=option1>option 1</option> <option value=option2>option 2</option>
We have two dropdowns that according to your selection it changes part of the
I have a pretty simple MVC 2 form. It has two dropdowns, user and
I have two select menus (#id1 and #id2) that, when validated as containing a

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.