How do I get the value of a record selected by combobox using php [closed]

0

If anyone has an answer, I will thank them very much. I want to get the value of the selected record to show it in the same form from where I select the record.

This is my code:

<tr>
   <td scope="row" align="right">Nombre de Carrera:  </td>
   <td> <select name="carrera" onchange="">
   <option value="" selected>Selecciona una carrera</option>

    <?php 

$res=mysql_query($query);

    while($row=mysql_fetch_array($res))
    {
        ?>
            <option value="<?php echo $row['idcarrera'];?>'" selected="true"><?=$row['nombrecarrera']?></option>

    <?php } $idcarrera=$row['idcarrera']?>


    </select></td>
    </td>
  </tr>
    
asked by celco 28.06.2018 в 18:01
source

1 answer

1

My recommendation is that you put an id to the select, then you take the value with javascript:

var optCarrera = document.getElementById("elemento")
optCarrera.onchange = function(){
  alert(this.value);
}
<tr>
   <td scope="row" align="right">Nombre de Carrera:  </td>
   <td> 
      <select name="carrera" onchange="" id="elemento">
        <option value="0">Selecciona una carrera</option>
        <option value="1">Carrera 1</option>
        <option value="2">Carrera 2</option>
        <option value="3">Carrera 3</option>
      </select>
    </td>
  </tr>
    
answered by 28.06.2018 в 19:14