How to use the select form select in html page [closed]

1

I need to know what the user chose within <select> .

In the code below I need to know the collection code chosen by the user, to show the items that have not yet been collected.

<p align="left">Nº da Coleta <br>
<?php 
      echo ("<select name=\"colCodigo\">");

      $coletas = new Coletas();
      $coletas = $coletas->distinct();

      foreach ($coletas as $c) 
      {
          $cod = $c["colCodigo"];

          echo ("<option>$cod</option>");
      }
      echo ("</select>");
?>
    
asked by anonymous 14.09.2016 / 08:13

1 answer

5

Assuming your table has a id for each collection, your code should look like this:

<p align="left">Nº da Coleta <br>
<?php 
      echo ("<select name=\"colCodigo\">");

      $coletas = new Coletas();
      $coletas = $coletas->distinct();

      foreach ($coletas as $c) 
      {
          $cod = $c["colCodigo"];

          echo ("<option value='".$c["id"]."'>$cod</option>");
      }
      echo ("</select>");
?>

So when your form is submitted, you can get the value of select .

Assuming it is sent via POST you can get: $valor=$_POST['colCodigo'];

    
14.09.2016 / 13:04