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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:07:55+00:00 2026-06-08T16:07:55+00:00

I am using Mika Tuupola Chained Selects jQuery plugin to build a chained select/dropdown

  • 0

I am using Mika Tuupola Chained Selects jQuery plugin to build a chained select/dropdown for my website.

I am dynamically pulling the options from two databases categories and subcategories like this:

categories:

<?php
  $query="SELECT * FROM categories";
  $result = mysql_query ($query);
  echo"<select name='cselect1' id='cat'><option value=''>Please Select A Category</option>";
  // printing the list box select command
  while($catinfo=mysql_fetch_array($result)){//Array or records stored in $nt
  echo "<option value=\"".htmlspecialchars($catinfo['number'])."\">".$catinfo['cat']."</option>";

  }

  echo"</select>";
?>

and subcategories

<?php
  $query="SELECT * FROM subcategories";
  $result = mysql_query ($query);
  echo"<select name='sselect1' id='subcat'><option value=''>Sub Category</option>";
  // printing the list box select command
  while($catinfo=mysql_fetch_array($result)){//Array or records stored in $nt
  echo "<option value='".htmlspecialchars($catinfo['subcat'])."' class='".$catinfo['catnumber']."'>".$catinfo['subcat']."</option>";
  }

  echo"</select>";
?>

which echos out something like this:

<select id="cat" name="cselect1">
    <option value="0">Please Select A Category</option>
    <option value="1">Restaurants</option>
    <option value="2">Food</option>
    <option value="3">Nightlife</option>
    <option value="4">Shops</option>
</select>

<select id="subcat" name="sselect1">
    <option value="">Sub Category</option>
    <option class="1" value="American">American</option>
    <option class="2" value="Specialty Food">Specialty Food</option>
    <option class="3" value="Bars">Bars</option>
    <option class="4" value="Computers">Computers</option>
</select>

and here is my jquery:

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="../public/scripts/chain.js" type="text/javascript"></script>
<script type="text/javascript">
        $("#subcat").chained("#cat");
</script>

But for some reason, it’s not working? Why is this?

Thanks for all help on this!

  • 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-08T16:08:00+00:00Added an answer on June 8, 2026 at 4:08 pm
    <script type="text/javascript">
        $(document).ready(function(){
            $("#subcat").chained("#cat");
        });
    </script>
    

    In your case you have been doing:

    <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
    <script src="../public/scripts/chain.js" type="text/javascript"></script>
    <script type="text/javascript">
            $("#subcat").chained("#cat");
    </script>
    

    At the time $("#subcat").chained("#cat"); is called the document is still getting downloaded and parsed into DOM, also the jQuery files, chain.js may not be downloaded yet.

    The <select id="cat" name="cselect1"> and the other div is also not parsed at this moment. So doing $("#subcat") is referrring to something thats going to exist in future. So your code fails.

    One solution that existed for this is to do all such operations accessing elements be done after the element in HTML, so moving such scripts to end of file before closing body will help.

    But that is not recommended as you have better solutions now, most modern browsers support an DOMready event that is triggered once everything is downloaded, parsed and DOM is ready. the $(document).ready(function(){..}); is a cross browser implementation of this DOM rady event by jQuery.

    Al the below are variants of Document.ready, but does the same thing.

    $(document).ready(function () {
    });  
    
    $().ready(function () {
    }); 
    
    $(function () {
    });     
    
    jQuery(function ($) {
    });
    

    In a nutshell, writing code inside $(document).ready(function(){..}); makes sure that, everything has completed downloading and DOM is ready at the time our code is executed.

    Note : When i say everything is downloaded, it doesnt cover images and other data that is not required to prepeare the DOM. window.load(function(){...}); is the event that is triggered once everything including images are downloaded and page has loaded completely.

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

Sidebar

Related Questions

I'm using Mika Tuupola's Lazy Load plugin http://www.appelsiini.net/projects/lazyload to delay loading images as you
Using JQuery, how do I select all elements with class x within an element
Using the following query: SELECT sum(severity) as Score, DATE_FORMAT(LAST_UPDATE,%Y-%m) as score_date FROM missingpatches GROUP
Using jQuery the jquery plugin along with the easing plugin. I have a series
Using JPA, I want to select all Log objects for a specific actiontype. From
Using SQL Server 2008 R2 we are looking for a way to select the
Using jQuery, one can easily find out whether a particular element is visible using
Using mercurial, I've run into an odd problem where a line from one committer
Using php/html, I want to retrieve email addresses (plus other information) from MySQL and
(Using MVC 2) From inside my controller action, I need to display the url:

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.