Select with description

0

I would like that when selecting a field in the form with a Select the description of the acronym would come out, which I already got, what happens is that I would like the description not to enter the ID of the field, ie , if I select a project in a refillable author field, only the acronyms of the project are selected but in this chaos I am filled with the description as well, and I would like to know if it is possible that this will not happen, that it will show the description but that it will not enter the ID or NAME of TD .

<td>
    <select class="form-control" name="acro_proyecto" id="acro_proyecto"  onchange="change_documento1();  change_documento2(); change_documento9(); change_documento11()" required="">
            <option value=""><?php echo isset($obj_categoria) ? $obj_categoria->__GET('proyecto') : ''; ?> </option> 
            <?php
            $pdo = new PDO('mysql:host=localhost;dbname=*;charset=UTF8', '*', '*');
                                    $pdo->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
            $stmt = $pdo->prepare('Select * from proyectos order by acro_proyecto');
            $stmt->execute();
            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            echo '<option name="' .
            ($row['acro_proyecto']) . '">' .  $row['acro_proyecto'] . '<p>' . '(' .$row['descripcion'] . ')'. '</p>'. '</option>'   ;
            }
            ?>
     </select>
</td>

In the previous one it is inside the option that's why it comes out in the select so to say it here I have it out and it does not show it to me:

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
      echo '<option name="' .
      ($row['acro_proyecto']) . '">' .  $row['acro_proyecto'] . '</option>' . '<p>' . '(' .$row['descripcion'] . ')'. '</p>'   ;
      }
    
asked by Alberto Cepero de Andrés 24.07.2017 в 12:18
source

2 answers

1

I really did not understand you, but let's see your code.

Actually the name attribute must not be part of the Option, instead it must go in the Select, value is an attribute that gives us the value of the selected option.

Neither do you need the () to concatenate or use echo.

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
      echo '<option value="' .$row['acro_proyecto']. '">' . 
        $row['acro_proyecto'] . '</option>' .

        '<option disabled>' . '(' .$row['descripcion'] . ')'.
         '</option>';
      }

Another thing, it is not advisable to have many similar functions but with a different name, I say it change_documento1 () Yes it is the same function but just change the number you can do the function so that it receives the number as a parameter instead of writing a thousand times the same function

That is to say

function change_documento( idDocumento)
{ 
    alert ( idDocumento );
}

change_documento(1);
change_documento(5);

In this way we define it once and we pass the IDE that we want

    
answered by 24.07.2017 / 15:03
source
0

A little rudimentary but functional,

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
      echo '<option name="' .
      ($row['acro_proyecto']) . '">' .  $row['acro_proyecto'] . '</option>' . '<option disabled>' . '(' .$row['descripcion'] . ')'. '</option>';
      }
      ?>

I add another option to which I indicated that it will be disabled so that it can not be selected and I have the acronym and just below its description.

    
answered by 24.07.2017 в 12:27