php中下拉列表选择后,如何在另一个文本框中显示出与选择项匹配的数据库中的值?

还有,如何获得用php获取下拉列表的值

<?php
$query="select * from test where 1";
$query1=mysql_query($query) or die(mysql_error());
if(mysql_num_rows($query1) > 0){
$row = mysql_fetch_row($query1);
@mysql_free_result($query1);
?>
<html>
<script>
function areas_change(th){

//alert(document.getElementById('areas_str').value);
if(2==th){
//alert(document.getElementById('city').value);
document.getElementById('area').value=document.getElementById('city').value;
}
else if(1==th)
document.getElementById('area').value=document.getElementById('pro').value;
else
document.getElementById('area').value=document.getElementById('county').value;

}
</script>
<body>
<select name="areas" id="areas" onchange=" areas_change(this.value);">
<option value="3" selected="selected">请选择</option>
<option value="<?php echo $row[0];?>">县级</option>
<option value="2">市级</option>
<option value="1">省级</option>
</select>
<input type="hidden" readonly name="city" id="city" value='123'>
<input type="hidden" name="pro" id="pro" value='123'>

<input type="hidden" name="county" id="county" value='213'>
<input type="text" maxlength='18' name="area" id="area" value='132' onafterpaste="this.value=this.value.replace(/\'/g,'')">
</body>
</html>
如何获得下拉列表的值,只需要$_POST['areas']; 这个例子是php和html代码混合的例子,是事先提取数据库的值放到select的value中,然后change后用于post提交。
当然你可以用ajax进行异步调用
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-08-14
1. 那个有两种方法...
一. 在Select选择的时候..做form的submit..然后在文本框内打印值
二. 采用ajax

2. 按form的method方式..用$_GET或者$_POST
第2个回答  2009-08-14
<select name="aitem" id="aitem">
<option value="请选择" selected>请选择</option>
<option value="小贴士" >小贴士</option>
<option value="房间贴士" >房间贴士</option>
<option value="咨询信息" >咨询信息</option>
</select>
利用表单提交 只在提取
$aitem=$_POST[aitem];
相似回答