请教一个下拉菜单和文本框联动的问题
下面的代码如果把<form>去掉的话没有问题,加上<form>就会出现'this.SelTest.selectedIndex' 为空或不是对象的错误,但没有<form>的话就没法提交了,请问应该怎样改呢?
<html>
<head>
</head>
<script language="javascript" >
function SelTest_Change()
{
var SelIdx=this.SelTest.selectedIndex;
var selOpt=this.SelTest.options[SelIdx];
switch(selOpt.value)
{
case "A":
this.ShowText.style.display="none";
break;
case "B":
this.ShowText.style.display="inline";
break;
}
}
</script>
<body>
<form name="form1" method="post" action="lian.asp">
<select name="SelTest" onChange="SelTest_Change();" >
<option selected >请选择</option>
<option value="A">A</option>
<option value="B">B</option>
</select>
<div id="ShowText" style="display:none" ><input type="text" name="TxtTest" ></div>
</form>
</body>
</html>
<head>
</head>
<script language="javascript" >
function SelTest_Change()
{
var SelIdx=this.SelTest.selectedIndex;
var selOpt=this.SelTest.options[SelIdx];
switch(selOpt.value)
{
case "A":
this.ShowText.style.display="none";
break;
case "B":
this.ShowText.style.display="inline";
break;
}
}
</script>
<body>
<form name="form1" method="post" action="lian.asp">
<select name="SelTest" onChange="SelTest_Change();" >
<option selected >请选择</option>
<option value="A">A</option>
<option value="B">B</option>
</select>
<div id="ShowText" style="display:none" ><input type="text" name="TxtTest" ></div>
</form>
</body>
</html>