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

  • Home
  • SEARCH
  • 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 6702885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:06:21+00:00 2026-05-26T07:06:21+00:00

PHP/HTML <select id=n name=userListingCateory> <option disabled=disabled>Category…</option> <?php while($row = $sth2->fetch(PDO::FETCH_ASSOC)) {echo <option value=. $row[‘catID’]

  • 0

PHP/HTML

            <select id="n" name="userListingCateory">
      <option  disabled="disabled">Category...</option>
              <?php while($row = $sth2->fetch(PDO::FETCH_ASSOC))
              {echo "<option value=". $row['catID'] . ">" .$row['catName']."</option>";}
            unset($sth2);
            ?>
            </select> 
            <select id="n" name="userListingSubCateory">
      <option  disabled="disabled">Sub-Category...</option>
              <?php while($row = $sth3->fetch(PDO::FETCH_ASSOC))
              {echo "<option value=". $row['scatID'] . ">" .$row['scatName']."</option>";}
            unset($sth3);
            ?>

This gives me correctly two dropdowns with values from database.
https://i.stack.imgur.com/s9rWB.png https://i.stack.imgur.com/4psBC.png (admin please show)
How do I get this (using JS or PHP) to make the ‘Sub-Category’ disabled until a ‘Category’ is selected, then based on the value chosen in Category, will enable the ‘sub-category’ dropdown to come up with the values pertaining to the category initially chosen??

The two database tables for category and subcategory are:
Category: catID (Pk)
catName

Subcategory: scatID (PK)
scatName

(admin please show images)

Anyone?

  • 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-05-26T07:06:22+00:00Added an answer on May 26, 2026 at 7:06 am

    First of all, you are mixing two independant states and two critical parts of an application.

    When a script is generated it is sent to the browser and then there is a downtime until the response comes back. But you seem to understand that.

    The other critical part is to rip out the data logic from your script from the view part. No need to have any complex MVC framework to do that, just at least get your data for both parts in the top of your script will make it simpler.

    Here is an approximate way to do it, adapt it to your technology or framework:

    <?php
    
    //Read the data
    $data = $data2 = array();
    $datares = mysql_query('SELECT * FROM categories');
    $data2res = mysql_query('SELECT * FROM subcategories');
    while($datarow = mysql_fetch_assoc($datares)){
        $data[$datarow['id']] = $datarow;
    }
    while($data2row = mysql_fetch_assoc($data2res)){
        $data2[$data2row['parentid']][$data2row['id']] = $data2row;
    }
    
    //If this is a postback
    if($_SERVER['REQUEST_METHOD'] == 'POST'){
        if(isset($_POST['userListingCateory']) && in_array($_POST['userListingCateory'], array_keys($data))){
            $subcategorydata = $data2[$_POST['userListingCategory']];
        }
    }
    
    /* put all the rest of the code you think you need here */
    
    ?>
    <select name="userListingCategory">
    <?php foreach($data as $dataitem){ ?>
        <option value="<?php echo $dataitem['id']; ?>"<?php if($_POST['userListingCategory'] == $dataitem['id']){ echo ' selected="SELECTED"'; } ?> ><?php echo $dataitem['label']; ?></option>
    <?php } ?>
    </select>
    
    <?php if(isset($subcategorydata)){ ?>
    <select name="userListingSubCateory">
    <?php foreach($subcategorydata as $dataitem){ ?>
        <option value="<?php echo $dataitem['id']; ?>"<?php if($_POST['userListingSubCateory'] == $dataitem['id']){ echo ' selected="SELECTED"'; } ?> ><?php echo $dataitem['label']; ?></option>
    <?php } ?>
    </select>
    <?php } ?>
    

    I hope this will get you started…

    Good luck

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

Sidebar

Related Questions

I currently have a HTML select box like below. <select name=item_1> <option value=0>Choose one...</option>
PHP/MYSQL <div style=width:810px; margin:inherit; padding-left:170px;> <select style=width:300px; id=n name=userListingCateory> <option disabled=disabled>Category...</option> <?php while($row =
alt text http://www.freeimagehosting.net/image.php?a55fa98f01.jpg Hi I am trying to use a HTML select box with
search.php $text = $mysqli->$_POST['term']; $query = SELECT name FROM males WHERE name LIKE '%
I have an HTML select element created in PHP. I want to add $car
Which is better from a security standpoint when populating an HTML select box? Option
I want to use php array for HTML select list. In this case it
I have to deploy my php/html/css/etc code to multiple servers and i am looking
I want to use this function: http://www.frankmacdonald.co.uk/php/post-to-wordpress-with-php.html Its used to post to Wordpress using
I've got PHP and HTML code stored in a database table. When I get

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.