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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:33:20+00:00 2026-06-06T16:33:20+00:00

I have two drop down menus where the options are not get from the

  • 0

I have two drop down menus where the options are not get from the database.

The first one, lets the user to select a category.

<select name="category">
    <option value="0">None</option>
    <option value="1">First</option>
    <option value="2">Second</option>
    <option value="3">Third</option>
    <option value="4">Fourth</option>
</select>

The options of the second, are depended from the choice in the first dropdown menu. For example, if the user chooses the First option then the second dropdown will show

<select name="items">
    <option value="3">Smartphone</option>
    <option value="8">Charger</option>
</select>

but when the user change his mind, or select the second option first, then the second dropdown will now show

<select name="items">
    <option value="1">Basketball</option>
    <option value="4">Volleyball</option>
</select>

My question is how can I achieve this ? Can this be done without using a database?

Thank you!

  • 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-06T16:33:21+00:00Added an answer on June 6, 2026 at 4:33 pm

    See below to see the Working Example without using a Database.

    Working Example Using MySQL Database

    If you wanna connect it using Database, yeah, it is surely possible. Consider this table:

    CREATE TABLE `contents` (
        `id` INT PRIMARY KEY AUTO_INCREMENT,
        `name` VARCHAR (255),
        `parent` INT DEFAULT 0
    );
    
    INSERT INTO `contents` (`name`, `parent`) VALUES
        ('Names', 0),
        ('Places', 0),
        ('Animals', 0),
        ('Praveen', 1),
        ('Bill Gates', 1),
        ('Steve Jobs', 1),
        ('India', 2),
        ('New York', 2),
        ('London', 2),
        ('Singapore', 2),
        ('Cat', 3),
        ('Dog', 3),
        ('Tiger', 3),
        ('Deer', 3)
    

    Table Structure

    +----+------------+--------+
    | id | name       | parent |
    +----+------------+--------+
    |  1 | Names      |      0 |
    |  2 | Places     |      0 |
    |  3 | Animals    |      0 |
    |  4 | Praveen    |      1 |
    |  5 | Bill Gates |      1 |
    |  6 | Steve Jobs |      1 |
    |  7 | India      |      2 |
    |  8 | New York   |      2 |
    |  9 | London     |      2 |
    | 10 | Singapore  |      2 |
    | 11 | Cat        |      3 |
    | 12 | Dog        |      3 |
    | 13 | Tiger      |      3 |
    | 14 | Deer       |      3 |
    +----+------------+--------+
    

    Initial HTML & PHP Code

    Now, lets use PHP to first populate the initial <select>:

    <?php
        mysql_connect();
        mysql_select_db("contents");
        $result = mysql_query("SELECT * FROM `contents` WHERE `parent` = 0");
        while(($data = mysql_fetch_array($result)) !== false)
            echo '<option value="', $data['id'],'">', $data['name'],'</option>'
    ?>
    

    Now the <select> is ready. With its onchange function, we can fire an AJAX event to get the new <select> with the data provided by the parent <select>.

    <select onchange="ajaxfunction(this.value)">
        <!-- Options would have been initially populated here -->
    </select>
    

    Now for the jQuery function, you can do this way:

    <script type="text/javascript">
        function ajaxfunction(parent)
        {
            $.ajax({
                url: 'process.php?parent=' + parent;
                success: function(data) {
                    $("#sub").html(data);
                }
            });
        }
    </script>
    

    In the HTML, after the <select>, you need to give another select with an id as sub.

    <select onchange="ajaxfunction(this.value)">
        <!-- Options would have been initially populated here -->
    </select>
    <select id="sub"></select>
    

    Processing PHP Source Code

    Finally the source code of process.php:

    <?php
        mysql_connect();
        mysql_select_db("contents");
        $result = mysql_query("SELECT * FROM `contents` WHERE `parent` = " . mysql_real_escape_string($_GET["parent"]));
        while(($data = mysql_fetch_array($result)) !== false)
            echo '<option value="', $data['id'],'">', $data['name'],'</option>'
    ?>
    

    Working Example without using a Database

    You just need to replace this in the PHP.

    <?php
        $parent = array("Name", "Place", "Animals");
        foreach ($parent as $id => $name)
            echo '<option value="s', $id,'">', $name,'</option>'
    ?>
    

    And for the process.php:

    <?php
        $parent = array("Name", "Place", "Animals");
        $s0 = array("Praveen", "Bill Gates", "Steve Jobs");
        foreach (${$_GET["parent"]} as $id => $name)
            echo '<option value="', $data['id'],'">', $data['name'],'</option>'
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two dropdown list. first drop down:1 enter code here <form:select path=custName id=custName>
I have one drop down list in my page, which contains two options. What
I have a form with two text boxes, one select drop down and one
I have a drop down menu, with two options: <select name="chs" value="" id =
I have two drop down menus, one of which I am trying to replace
I have two drop down boxes in my program. When you select an item
In my application i have two drop down boxes first box had origin second
I have a user control in a master page with two drop down lists.
I have the following drop down menu: <select id=target> <option value=0>Zero ($123.45)</option> <option value=1>One
I have three drop down menus that query a MYSQL database depending on what

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.