collect value option php

-2

I have a code similar to this one:

 echo "<select name='$nombre' id='$id'>";
 echo "<option value='0'>Seleccione opcion</option>";
 while ($row=mysql_fetch_assoc($result)){
     $id= $row[$campo_valor];
     $texto= $row[$campo_visual];
     $sel="";

     if ($default==$id){
         $sel="Selected";
     }
     echo "\n <option value='$id' $sel>$texto</option>";
 }
 echo "</select>";

I would like to know how to collect the value of the option (value="$ id"), since by picking up the value of the select, the result is 0.

Thank you very much

    
asked by Sara 06.03.2018 в 16:46
source

3 answers

0

there you have an example, I do not understand your code

<div class="form-group col-md-3">
<label class="control-label">Puesto</label>
<select class="form-control requeridoPuesto input-sm selectpicker" data-live-search="true" name="puesto" id="puesto">
<option>Seleccione</option>
<?php 
foreach ($puestos as $puesto){
?>                            
<option if($puesto['puesto']=='programador'){ echo 'selected';} value="<?php echo $puesto['idPuesto']?>"><?php echo $puesto['nombre']?></option>
<?php
}
?> 
</select> 
</div>

pick up value of the select

$puesto= $_POST["puesto"];
    
answered by 06.03.2018 в 16:59
0

For example, given this select:

<select id='test'>
    <option selected value="A">B</option>
</select>

So, if you want A is:

alert(document.getElementById("test").value);

And if you want B it's:

alert(document.getElementById("test").text);

That is, value returns the value of the option as long as it text the text of it.

    
answered by 06.03.2018 в 17:16
0

Sorry for not answering, it was silly what was happening to me. I did not pick up the "name" of why the form did not close in the place it should, I realized when I used to inspect item.

    
answered by 09.03.2018 в 11:29