0

I'm trying to get the selected value from my comboBox in PHP inside a while loop fetching MySQL results. How could I do it?

<?php
    include ("../conex.php");

    $conSql = ("CALL LISTAR_ASIGNATURAS()");
    $datos=mysqli_query($conex,$conSql);

    echo "<a style='font-size:16px;' href='../index.html'>Volver Atras</a>";
    echo " "; 
    echo "<select name='asigna' id='y' style='width:280px; height:23px;'>"; 
    echo "<option value='0'>Seleccione una Asignatura...</option>";

    while($fila=mysqli_fetch_assoc($datos)) {   
        echo "<option value='".$fila["cod_asignatura"]."'>".$fila["nom_asignatura"]. "</option>";
    }
    echo "</select>";
    echo " ";

    echo "<input type='submit' onclick=location.href='listarasig2.php?codA=".$selected_val."' value='Buscar'>";
?>
Midori_hige
  • 311
  • 6
  • 21

1 Answers1

0

You could do something like this in jQuery.

$('#testCombo').change(function() {
  var cboValue = this.value;
  var link;
  link = "location.href='listarasig2.php?codA=" + cboValue;
  $('#testSubmit').attr('onclick', link);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="testCombo">
  <option value="0">test0</option>
  <option value="1">test1</option>
  <option value="2">test2</option>
  <option value="3">test3</option>
</select>

<input type="submit" id="testSubmit" />

or if you still want to use PHP, you could do something like this.

echo "<a style='font-size:16px;' href='../index.html'>Volver Atras</a>";
echo " <form action='' method='get'>";
echo "<select name='asigna' id='y' style='width:280px; height:23px;'>";
echo "<option value='0'>Seleccione una Asignatura...</option>";
while ($fila = mysqli_fetch_assoc($datos)) {
  echo "<option value='".$fila["cod_asignatura"].
  "'>".$fila["nom_asignatura"].
  "</option>";
}
echo "</select>";
echo " ";
echo "<input type='submit' value='Get Value'>";
echo "</form>";
echo "<input type='submit' onclick=location.href='listarasig2.php?codA=".$_GET['asigna'].
"' value='Buscar'>";
Mark Vincent Manjac
  • 507
  • 1
  • 6
  • 27