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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:29:32+00:00 2026-06-07T15:29:32+00:00

I have the following code: $(document).ready(function () { $(#comboSubsidiary).combobox({ selected: function (event, ui) {

  • 0

I have the following code:

$(document).ready(function () {

        $("#comboSubsidiary").combobox({

            selected: function (event, ui) {
                var subsidiary = $("#comboSubsidiary").select().val();

                switch (subsidiary) {

                    case (subsidiary = "GH"):
                        $.ajax({
                            type: "GET",
                            url: "GHworkerType.xml",
                            dataType: "xml",
                            success: function (xml) {
                                var select = $('#comboWorkerType');
                                $(xml).find('type').each(function () {
                                    var type = $(this).find('type').text();
                                    select.append("" + type + "");
                                    var id = $(this).attr('id');
                                    var name = $(this).find('name').text();
                                    var rate = $(this).find('rate').text();
                                    if (name == "Cust" || name == "Int") {
                                        $('<optgroup label="' + name + '"></optgroup>').html(name).appendTo('#comboWorkerType');
                                    }
                                    else {
                                        $('<option>' + name + '</option>').html(name).appendTo('#comboWorkerType');
                                    }

                                });


                                select.children(":first").text("Select worker type").attr("selected", true);

                            }
                        });
                        break;

                    case (subsidiary = "GT"):
                        alert('Alert');
                        break;

                }
            }
        });
});

HTML:

<div class="comboTravel">
     <select id="comboSubsidiary" >
       <optgroup label="Cust">
        <option>Select subsidiary</option>
       </optgroup>
     </select>
</div>

this is the XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<worker>
    <type>
        <name>Cust</name>
        <rate>Cust</rate>
    </type>
    <type>
        <name>1</name>
        <rate>75</rate>
    </type>
    <type>
        <name>2</name>
        <rate>83</rate>
    </type>
    <type>
        <name>3</name>
        <rate>105</rate>
    </type>
    <type>
        <name>4</name>
        <rate>115</rate>
    </type>
    <type>
        <name>5</name>
        <rate>0</rate>
    </type>
    <type>
        <name>Int</name>
        <rate>Int</rate>
    </type>
    <type>
        <name>1</name>
        <rate>75</rate>
    </type>
    <type>
        <name>2</name>
        <rate>83</rate>
    </type>
    <type>
        <name>3</name>
        <rate>105</rate>
    </type>
    <type>
        <name>4</name>
        <rate>115</rate>
    </type>
    <type>
        <name>5</name>
        <rate>0</rate>
    </type>
</worker>

I want the combobox to show Cust and Int as optgroups. How can I get this to work?

At the moment all xml nodes were correctly displayed in the combobox but the two optiongroups aren’t displayed and everything which is included to the optiongroups isn’t displayed in the combobox.

  • 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-07T15:29:34+00:00Added an answer on June 7, 2026 at 3:29 pm

    Sorry it is not a complete solution but the standard combobox does not allow loading data remotely, so rather than reinvent, here are some alternatives.

    The answer to jQuery UI autocomplete (combobox): how to fill it with the result of an AJAX request? contains modified combobox code in which you can specify a value array or remote source. In my opinion the jQueryUI combobox is really a hack and does not seem to be considered a first class widget.

    You might have better luck using http://ivaynberg.github.com/select2/ which (again, in my opinion) has a richer API, looks cleaner and is overall a better UX. You will need to supply a formatResult function to display your custom data but there are plenty of examples on the aforementioned link.

    However, just one caveat is that <optgroup> support has only recently be added, so you will need the latest Select2 3.0 build, which could be unstable.

    Hope this helps 🙂

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

Sidebar

Related Questions

I have the following code, see below: $(document).ready(function(){ var prefixNumber = $('.numeric').val(); if(prefixNumber.match(????){ prefixNumber.addClass('.field-error');
I have the following code: $(document).ready(function() { var id = 'cbx'; var idPrefix =
I have the following JQuery code: $(document).ready(function () { var $containerHeight = $(window).height(); if
I have the following code: $(document).ready(function() { $('.container').ready(function() { var v = new Video($(this));
i have the following jquery code: $(document).ready(function() { $('.restrictiveOptions input[type!=checkbox], .restrictiveOptions select').change(function() { //
I have the following code $(document).ready(function() { // When change the value in select
I have the following code which works: $(document).ready(function() { var xhr = false; func_two();
I have the following code: $(document).ready(function() { var $body = $(body); for (var i
I have the following code in my head jQuery(document).ready(function() { var pic = 0;
I have the following code: $(document).ready(function () { $('div.env').each(function (index, item) { var vm

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.