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

227
Visualizações
Drop down menu with search bar in prestashop with JQuery

i am trying to make a drop down menu with a search bar using JQUERY in prestashop. The drop down menu fetches the data from database but the search bar doesnt appear. This is my code:

 $sql = "SELECT id_category, name FROM ps_category_lang";
        $result = $conn->query($sql);
        
        if ($result->num_rows > 0) {
            $html.="<select class='chosen' id='chosen'>";
          while($row = $result->fetch_assoc()) {
           $id = $row["id_category"];
           $name = $row["name"];
           $html.= "<option value='$id'>$id - $name</option>";
          }
          $html.="</select>";
        } 
        else 
        {
            $html .="<p>0 result</p>";
        }
        $conn->close();

And this is the javascript:

<script type="text/javascript">
      $(".chosen").chosen();
</script>

And this are functions i have called:

<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.5.1/chosen.min.css">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.5.1/chosen.jquery.min.js"></script>
</head>

This is how its supposed to look like:

enter image description here

and this is how it looks like

enter image description here

Any suggestion would be great, thank you in advance.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I found your problem you should put the javascript code under the part so it can work.

$sql = "SELECT id_category, name FROM ps_category_lang"; $result = $conn->query($sql);

        if ($result->num_rows > 0) {
            $html.="<select class='chosen' id='chosen'>";
          while($row = $result->fetch_assoc()) {
           $id = $row["id_category"];
           $name = $row["name"];
           $html.= "<option value='$id'>$id - $name</option>";
          }
          $html.="</select>";
           **$html.= "<script type='text/javascript'>
          $('.chosen').chosen();
         </script>";**
        } 
        else 
        {
            $html .="<p>0 result</p>";
        }
        $conn->close();
over 4 years ago · Santiago Trujillo Relatório

0

You replaced all the element with your output... You should append your result to the search element

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