我试图从PHP中的comboBox中获取所选值,并在while循环中获取MySQL结果。我怎么能这样做?
<?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'>";
?>
答案 0 :(得分:0)
你可以在jQuery中做这样的事情。
$('#testCombo').change(function() {
var cboValue = this.value;
var link;
link = "location.href='listarasig2.php?codA=" + cboValue;
$('#testSubmit').attr('onclick', link);
});
&#13;
<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" />
&#13;
或者如果你仍然想使用PHP,你可以这样做。
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'>";
&#13;