我想从Combobox中选择一个学年,然后用它来搜索所选年份的课程信。但我需要将所选文本放入变量中。
$yeardb = "SELECT DISTINCT `year` FROM `class`";
$do_year = mysqli_query($connectDB, $yeardb);
$num_year = mysqli_num_rows($do_year);
Year:
<form method="POST" >
<select id="yearCB" name="year" onchange="document.getElementById('selected_text').value=this.options[this.selectedIndex].text">
<?php
for ($i=0; $i<$num_year; $i++)
{
$yr = mysqli_fetch_array($do_year);
echo'<option value="'.$i.'">'.$yr ['year'].'</option>';
}
?>
</select>
<input type="hidden" name="selected_text" id="selected_text" />
</form>
<?php
if(isset($_POST['selected_text']))
{
$Value = $_POST['year'];
$make = mysql_real_escape_string($_POST['selected_text']);
}
$classdb = "SELECT `class` FROM `classes` WHERE `year` =".$make;
$do_class = mysqli_query($connectDB, $classdb);
$num_class = mysqli_num_rows($do_class);
?>
答案 0 :(得分:0)
在JQuery中
<select id="yearCB" name="year" onchange="funName(this.value)">
</select>
<input type="hidden" name="selected_text" id="selected_text" />
function funName(val) `/*function to set value*/`
{
$("#selected_text").val(val);
}
答案 1 :(得分:0)
使用以下代码
this.options[this.options.selectedIndex].text
<select id="yearCB" name="year" onchange="document.getElementById('selected_text').value
=this.options[this.options.selectedIndex].text">