关于下拉菜单的onchange问题

sunnybj 2004-11-26 06:06:49
我使用了下面的语句实现到本页面的跳转传值,
<form name=form2 action="r3message_input.php">
<table border=1>
<tr><td><select name=language onChange="document.form2.submit();">
<option value=Japanese>Japanese</option>
<option value=Chinese>Chinese</option>
<option value=English>English</option>
</select></td></tr>
</form>
但是,onchange之后,下拉菜单的文本框中显示的内容没有改变,还是显示初始的值,请问我怎么做,才能既实现页面跳转,又实现下拉菜单的文本框中值的改变?

也就是,说下拉菜单的文本框中,开始显示的是A,onchange之后,让下拉菜单的文本框中显示B,这个怎么实现呢?
...全文
172 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
sunnybj 2004-11-27
还是不行,高手指点指点,谢谢啦
回复
wxq4100798 2004-11-26
加上下面一段

if(isset($_POST['language']))
{
$language = $_POST['language'];
}

<script language="javascript">
function checked(param)
{
var length = document.form2.language.length
for(i=0;i<length;i++)
{
if(document.form2.language[i].value == param)
{
document.form2.language[i].selected = true;
}
}
}
</script>


回复
janlon 2004-11-26
给你做个参考:
-------------------------------------------------------------------
<html>
<head>
<title>List</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<?
$link = mysql_connect("localhost","root","root");
mysql_select_db("test", $link );

$sql="select * from tbl_psort";
$query=mysql_query($sql,$link);
?>

<script language = "JavaScript">

var onecount;
onecount = 0;
subcat = new Array();
<?
$count=0;
while($rs=mysql_fetch_array($query)){
?>
subcat[<?=$count;?>] = new Array("<?=$rs['psor_name'];?>","<?=$rs['pcat_id'];?>","<?=$rs['psor_id'];?>","<?=$rs['areacode']?>","<?=$rs['zipcode']?>");
<?
$count++;
}
?>
onecount=<?=$count?>;

function GetCode(psor_nameId){
var psor_nameId=psor_nameId;
var i;
for(i=0;i < onecount; i++){
if(subcat[2] == psor_nameId){
document.creator.AreaCode.value = subcat[3];
document.creator.ZipCode.value = subcat[4];
}
}
}

function ClearCode(){
document.creator.AreaCode.value = '';
document.creator.ZipCode.value = '';
}

function getpsor_name(locationid)
{
document.creator.psor_name.length = 0;

var locationid=locationid;

var i;
document.creator.psor_name.options[0] = new Option('选择小类别','');
for (i=0;i < onecount; i++)
{
if (subcat[1] == locationid)
{
document.creator.psor_name.options[document.creator.psor_name.length] = new Option(subcat[0], subcat[2]);
}
}

}
</script>
</head>
<body>
<form name="creator" method="post" action="">
分类:<select name="pcat_name" onChange="getpsor_name(document.creator.pcat_name.options[document.creator.pcat_name.selectedIndex].value);ClearCode();" size="1">
<option selected>请选择大类别</option>
<?
$sql1= "select * from tbl_pcatalog";
$query=mysql_query($sql1,$link);
$a=mysql_num_rows($query);
while($rs1=mysql_fetch_array($query)){
?>
<option value="<?=$rs1['pcat_id'];?>"><?=$rs1['pcat_name'];?></option>
<?}?>
</select>
<select name="psor_name" onChange="GetCode(document.creator.psor_name.options[document.creator.psor_name.selectedIndex].value);">
<option selected value="">请选择小类别</option>
</select>
<INPUT TYPE="hidden" NAME="AreaCode"><INPUT TYPE="hidden" NAME="ZipCode">
</form>
</body>
</html>
<?
if(!empty($_POST['psor_name'])){
echo $_POST['psor_name'];
}
?>

#
# 数据表的结构 `tbl_pcatalog`
#

CREATE TABLE tbl_pcatalog (
pcat_id int(11) NOT NULL auto_increment,
pcat_name varchar(20) NOT NULL default '',
pcat_desc varchar(150) default NULL,
pcat_enname varchar(20) default NULL,
pcat_memo2 varchar(100) default NULL,
PRIMARY KEY (pcat_id)
) TYPE=MyISAM;
# --------------------------------------------------------

#
# 数据表的结构 `tbl_psort`
#

CREATE TABLE tbl_psort (
psor_id int(11) NOT NULL auto_increment,
pcat_name varchar(20) NOT NULL default '',
psor_name varchar(20) NOT NULL default '',
psor_desc varchar(150) default NULL,
psor_enname varchar(20) default NULL,
pcat_id int(11) default NULL,
PRIMARY KEY (psor_id)
) TYPE=MyISAM;
回复
qdsxm 2004-11-26
要用selected 要判断你选择了哪一个,然后提交之后再在<option>中将你选中的那个赋值selected
如果你用smarty模板的话就很简单了
<select name=language>
{html_options values=$cust_ids selected=$customer_id output=$cust_names}
</select>

直接$smarty->assign("customer_id",$language);就可以了
回复
相关推荐
发帖
基础编程
创建于2007-09-28

2.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
申请成为版主
帖子事件
创建了帖子
2004-11-26 06:06
社区公告
暂无公告