Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

121
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda