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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:29:04+00:00 2026-06-09T05:29:04+00:00

I have 2 drop-down menu forms ‘category’ and ‘sub-category’. in ‘category’ I have options

  • 0

I have 2 drop-down menu forms ‘category’ and ‘sub-category’. in ‘category’ I have options music and film and in the subcategories I have options ‘pop’ and ‘rock'(f1) and in film ‘comedy’and ‘drama'(f2). the problem is, with the code I have the subcategories for film should register as follows(cat,subcat): film-drama=2,5 and film-comedy=2,6 however they both register as 2,0 when entered in the mysql table. here is the code:

 <form action='submitsite.php' method='POST'>
 <table>
 <tr>
 <td>category(optional)</td>
 <td><select name='cat' id = "opts" onchange = "showForm()">
 <option value = "0">Select</option>
 <option value = "1">music </option>
 <option value = "2">film </option>
 </select> 

 <div id = "f1" style="display:none">
 <form name= "subcat">
 <select name='subcat' id = "opts" onchange = "showForm()">
 <option value = "0">Select</option>
 <option value = "3">pop</option>
 <option value = "4">rock </option>
 </select>
 </form>
 </div>

 <div id = "f2" style="display:none">
 <form name= "subcat">
 <select name='subcat' id = "opts" onchange = "showForm()">
 <option value = "0">Select</option>
 <option value = "5">comedy</option>
 <option value = "6">drama</option>
 </select>
 </form>
 </div>

 <script type = "text/javascript">
 function showForm()
{
 var selopt = document.getElementById("opts").value;
 if (selopt == 1) 
{
  document.getElementById("f1").style.display="block";
  document.getElementById("f2").style.display="none";
}
 if (selopt == 2) 
{
  document.getElementById("f2").style.display="block";
  document.getElementById("f1").style.display="none";
}

}

and here is the variable declarations and mysql query:

$cat=$_POST['cat'];
$subcat=$_POST['subcat'];

$sql="INSERT INTO favorites VALUES('$cat','$subcat')";

it’s not a mysql issue I just added that part to give a better overall picture.

  • 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-09T05:29:06+00:00Added an answer on June 9, 2026 at 5:29 am

    You can’t have nested forms in HTML. The markup is not valid and I guess you get unexpected behavior when submitting. The solution to this is using a single form. There’s more than one way to do this, but here’s one example:

    HTML code:

    <form action='submitsite.php' method='POST'>
    <table>
    <tr>
    <td>category(optional)</td>
    <td><select name='cat' id = "opts" onchange = "showForm()">
    <option value = "0">Select</option>
    <option value = "1">music </option>
    <option value = "2">film </option>
    </select> 
    
    <div id = "f1" style="display:none">
    <select name='subcat1' id = "opts" onchange = "showForm()">
    <option value = "0">Select</option>
    <option value = "3">pop</option>
    <option value = "4">rock </option>
    </select>
    </div>
    
    <div id = "f2" style="display:none">
    <select name='subcat2' id = "opts" onchange = "showForm()">
    <option value = "0">Select</option>
    <option value = "5">comedy</option>
    <option value = "6">drama</option>
    </select>
    </div>
    </form>
    ....
    

    PHP code:

    $cat = $_POST['cat'];
    $subcat = $_POST['subcat' . $cat];
    

    Keep in mind that all user-submitted values must be validated before being used further. In this case, you would check for is_numeric(), check to see if it’s in your accepted range of values and maybe cast to an int.

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

Sidebar

Related Questions

I have 2 drop down menus, the options in the second drop down menu
I have a drop down menu in java with 3 options and right next
I have a drop down menu which you can see here on jsfiddle .
I have a drop down menu. Has product types. Product types have associated value
I have a drop down menu, that a user selects a criteria from, based
I have a drop down menu which fills with some doc names. Now when
Currently have a drop down menu that is activated on a hover (from display:none
I have a drop down menu in an ASPX page along the lines of:
I have a drop down menu made with Jquery. Right now, if you hover
We have a drop-down menu of volumes in our UI, and I'd like to

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.