示范效果的是用 JS 把 Select 中的 value 填入 Textbox 中.
要读出数据库中的数据到下拉框中只要用php生成 下面这段就OK了<?php
$Citys = mysql_fetch_array($res); //先取出城市
.
.
.$Sections = mysql_fetch_array($res); //然后取出区
?>
where[0]= new comefrom("请选择省份名","请选择城市名");
where[1] = new comefrom("<?php echo $city[0]; ?>","
<?php
foreach($section as $c)
{
echo "|".$c;
}
?>
");
要读出数据库中的数据到下拉框中只要用php生成 下面这段就OK了<?php
$Citys = mysql_fetch_array($res); //先取出城市
.
.
.$Sections = mysql_fetch_array($res); //然后取出区
?>
where[0]= new comefrom("请选择省份名","请选择城市名");
where[1] = new comefrom("<?php echo $city[0]; ?>","
<?php
foreach($section as $c)
{
echo "|".$c;
}
?>
");
<option value="Title" selected>文章标题</option>
<option value="Content">文章内容</option>
<option value="Author">文章作者</option>
</select>
<select size="1" name="selectarttype">
<option value="" selected>所有类别</option>
<?php
$rs=mysql_query($artclasssql);
while($row=mysql_fetch_array($rs))
{
?>
<option value=<?php echo $row["className"];?>><?php echo $row["className"];?></option><? }?>
</select>
<?
require "function.php";
$query=mysql_query("select * from $fenlei where menu_parent='6'");
while($array=mysql_fetch_array($query))
//echo "|$array[name]";
?>
<form action="" method=post name="creator" enctype="multipart/form-data">
<script language="javascript">
<!--
var where = new Array(3);
function comefrom(loca,locacity) { this.loca = loca; this.locacity = locacity; }
where[0]= new comefrom("请选择省份名","请选择城市名");
where[1] = new comefrom("山西","|太原|大同|阳泉|长治|晋城|朔州|吕梁|忻州|晋中|临汾|运城");
where[2] = new comefrom("新建栏目","<?echo "|$array[name]";?>");
where[3] = new comefrom("山东","|济南|青岛|淄博|枣庄|东营|烟台|潍坊|济宁|泰安|威海|日照|莱芜|临沂|德州|聊城|滨州|菏泽");
function select() {
with(document.creator.province) { var loca2 = options[selectedIndex].value; }
for(i = 0;i < where.length;i ++) {
if (where[i].loca == loca2) {
loca3 = (where[i].locacity).split("|");
for(j = 0;j < loca3.length;j++)
{ with(document.creator.city)
{ length = loca3.length; options[j].text = loca3[j]; options[j].value = loca3[j]; var loca4=options[selectedIndex].value;}}
break;
}}
document.creator.newlocation.value=loca2+loca4;
}
function init() {
with(document.creator.province) {
length = where.length;
for(k=0;k<where.length;k++) { options[k].text = where[k].loca; options[k].value = where[k].loca; }
options[selectedIndex].text = where[0].loca; options[selectedIndex].value = where[0].loca;
}
with(document.creator.city) {
loca3 = (where[0].locacity).split("|");
length = loca3.length;
for(l=0;l<length;l++) { options[l].text = loca3[l]; options[l].value = loca3[l]; }
options[selectedIndex].text = loca3[0]; options[selectedIndex].value = loca3[0];
}}
-->
</script>
<body onload="init()">
<font color=#000000><b>来自:</b><br>请输入您所在国家的具体地方。此项可选<br><br>
省份 <select name="province" onChange = "select()"></select>
城市 <select name="city" onChange = "select()"></select><br>
我在 <input type=text name="newlocation" maxlength=12 size=12 style="font-weight: bold"> 不能超过12个字符(6个汉字)
</form>
这句话有问题,javascript和PHP之间不能传数组,只能传字符串,你需要转换一下!