<form id="filter" name="filter" method="post" action="">
<select id="college" name="fuel" onchange="changeValue();">
<option value="petrol">Petrol</option>
<option value="diesel">Diesel</option>
</select>
<p><input name="filter" type="button" value="Filter" /></p>
</form>
如果您想在表单提交中发布值,请像这样使用
$ctext = $_POST['fuel'];
$list = mysql_query("SELECT fuel_type from car WHERE fuel_type ='$ctext'");
$row = mysql_fetch_array($list);
//process $row
如果不想提交表单,可以在onchange事件中使用jquery... js代码
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function changeValue() {
var ctext = $("#college option:selected").val();
$.ajax({ url: "yourfile.php",
data: {"ctext":ctext},
type: 'post',
success: function(output) {
//display output here
}
});
}
你的文件.php
<?php
//connect to db
$ctext = $_POST['ctext'];
$list = mysql_query("SELECT fuel_type from car WHERE fuel_type ='$ctext'");
$row = mysql_fetch_array($list);
echo $row['fuel_type'];
?>