1个回答
2014-04-22
展开全部
<?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进行异步调用
$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进行异步调用
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询