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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:25:45+00:00 2026-06-09T06:25:45+00:00

I’m trying to implement chained ajax selects from this jQuery plugin: http://www.appelsiini.net/projects/chained I’m using

  • 0

I’m trying to implement chained ajax selects from this jQuery plugin: http://www.appelsiini.net/projects/chained

I’m using the remote method.

I have a problem where my select boxes show the “default” (blank) value last in the select as seen here:

This is a problem because I have 5 chains, so when the blank value isn’t selected by default, it does 5 sequential lookups. It also isn’t working like it shows on the demo page where the default value is selected by default instead of a real value.

A JSON request from my server returns this:

{"":"","1":"Test #1","2":"Test #2"}

So as you can see, it’s not the order that my JSON is returning.

This is my HTML:

<label class="control-label" for="branch">Branch</label>
<select id="branch" name="branch">
    <option value=""></option>
    <option value="1">Foo</option>
    <option value="2">Bar</option>
</select>
<label class="control-label" for="facility">Facility</label>
<select id="facility" name="facility">
    <option value=""></option>
</select>

<script src="/js/chained.js"></script>
<script>
    $(document).ready(function() {
        $("#facility").remoteChained("#branch", "/src/record.json.php");
    } );
</script>

So now I’m lost and since I can’t read/write JavaScript very well, I’m hoping someone can see the issue and help me out.

  • 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-09T06:25:48+00:00Added an answer on June 9, 2026 at 6:25 am

    It happens because,

    Chrome and probably Opera sort object properties automatically

    So your JSON also is sorted in for loop.

    var json = {"":"","1":"Test #1","2":"Test #2"};
    for(var i in json)
       console.log(i);
    
    /* Result : 1 2 (null) */
    

    DEMO

    Solution 1:

    If you change your index as string that will not be sorted.

    var json = {"":"","t1":"Test #1","t2":"Test #2"};
    for(var i in json)
       console.log(i);
    
    /* Result : (null) t1 t2 */
    

    DEMO

    Solution 2:

    Changing plug-in

    Here is the edited plugin code that works with array,

      /*
     * Remote Chained - jQuery AJAX(J) chained selects plugin
     *
     * Copyright (c) 2010-2011 Mika Tuupola
     *
     * Licensed under the MIT license:
     *   http://www.opensource.org/licenses/mit-license.php
     *
     */
    
    (function($) {
    
        $.fn.remoteChained = function(parent_selector, url, options) { 
    
            return this.each(function() {
    
                /* Save this to self because this changes when scope changes. */            
                var self   = this;
                var backup = $(self).clone();
    
                /* Handles maximum two parents now. */
                $(parent_selector).each(function() {
                    $(this).bind("change", function() {
    
                        /* Build data array from parents values. */
                        var data = {};
                        $(parent_selector).each(function() {
                            var id = $(this).attr("id");
                            var value = $(":selected", this).val();
                            data[id] = value;
                        });
    
                        $.getJSON(url, data, function(json) {
                            var selectedVal;
                            /* Clear the select. */
                            $("option", self).remove();
    
                            /* Add new options from json. */
                            for (var key in json.options) {
                                var k = json.options[key];
                                /* This sets the default selected. */
                                if ("selected" == k.name) {
                                    selectedVal = k.value;
                                    continue;
                                }
                                var option = $("<option />").val(k.value).append(k.name);
                                $(self).append(option);    
                            }
    
                            /* Loop option again to set selected. IE needed this... */ 
                            $(self).children().each(function() {
                                if ($(this).val() == selectedVal) {
                                    $(this).attr("selected", "selected");
                                }
                            });
    
                            /* If we have only the default value disable select. */
                            if (1 == $("option", self).size() && $(self).val() === "") {
                                $(self).attr("disabled", "disabled");
                            } else {
                                $(self).removeAttr("disabled");
                            }
    
                            /* Force updating the children. */
                            $(self).trigger("change");
    
                        });
                    });
    
                    /* Force updating the children. */
                    $(this).trigger("change");             
    
                });
            });
        };
    
        /* Alias for those who like to use more English like syntax. */
        $.fn.remoteChainedTo = $.fn.remoteChained;
    
    })(jQuery);
    

    To work with this updated plugin, you should use this JSON format,

    {
        "options" : [
          { "value" : "", "name" : ""},
          { "value" : "1", "name" : "Test #1"},
          { "value" : "2", "name" : "Test #2"},
        ]
    }
    

    If you want to set a default selected item (for example “Test #1” is selected), so you can do that like this,

    {
        "options" : [
          { "value" : "", "name" : ""},
          { "value" : "1", "name" : "Test #1"},
          { "value" : "2", "name" : "Test #2"},
          { "value" : "1", "name" : "selected"}
        ]
    }
    

    How can I use this edited plugin?

    Just clear all the code in /js/chained.js than paste the new one.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.