Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
Get id of a selected item from one combo box to another

I want to get the category_id of the selected category and pass it to next query of subcategory so the next combo box will contain subcategories according to the selected category. Can you please help me to do it. Here is my javascript, php and html code.

<script language="javascript" type="text/javascript">
  function showCompany(catid) {
      document.form.submit();
  }
</script>  



<select name="cat_id" id="cat_id" onChange="showCompany(this.value);">
  <option value="">--Select--</option>
                       <?php
                        $sql_row1 = mysqli_query($mysqli,"SELECT * from categories");
                       while($sql_res1=mysqli_fetch_array($sql_row1))
                       {
                       ?>
                       <option value="<?php echo $sql_res1["category_id"]; ?>"><?php echo $sql_res1["category"]; ?></option>
                        <?php
                        }
                        ?>
</select>
                       <select name="company_id" id="company_id">

           <option value="">--Select--</option>
           <?php
           $sql_row = mysqli_query($mysqli,"SELECT * from subcategories where category_id='$_REQUEST[cat_id]'");

           while($sql_res=mysqli_fetch_array($sql_row))
           {
           ?>
           <option value="<?php echo $sql_res["subcategory_id"]; ?>"><?php echo $sql_res["subcategory_name"]; ?></option>
           <?php
           }
           ?>
</select>
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Edit this line to this:

$sql_row = mysqli_query($mysqli,"SELECT * from subcategories where category_id='".$_REQUEST['cat_id']."'");

Providing $_REQUEST['cat_id'] has a value, it should now go in the query properly.

over 4 years ago · Santiago Trujillo Report

0

Try removing single quotes around $_REQUEST. may be the column type on DB is int. Try following code.

      <?php
       $cat_id=$_REQUEST['cat_id'];
       $sql_row = mysqli_query($mysqli,"SELECT * from subcategories where category_id=$cat_id");
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!