请问怎么用JS比较两个DropDownList选择项的索引值?
环境: VS.NET 2003 C# asp.net v1.1
程序:想用JS比较两个DropDownList选择项的索引值,如果ddl1.SelectedIndex > ddl2.SelectedIndex 则显示一个提示标签,否则隐藏该标签。
问题:Microsoft JScript 运行时错误: 对象不支持此属性或方法。
代码:
.cs:
在Page_Load()中:
// 在客户端返回控件ID
Page.RegisterStartupScript( "start ",
"function getDDL1()\n " +
"\n <script> \n " +
" return document.forms(0).item( ' " + this.ClientID + ": " + this.DDL1.ID + " ');\n " +
"}\n " +
"function getDDL2()\n " +
"{\n " +
" return document.forms(0).item( ' " + this.ClientID + ": " + this.DDL2.ID + " ');\n " +
"}\n " +
" </script> \n ");
//添加事件
DDL2.Attributes.Add( "onclick ", "CheckIcType() " );
下面是aspx页面JS代码:
<script language= "javascript ">
function CheckIcType()
{
if ( document.getElementByID(getIcTypeFrom()).SelectedIndex > document.getElementByID(getIcTypeTo()).SelectedIndex )
getLblIcType().visible = true;
else
getLblIcType().visible = false;
}
</script>
请问应该怎么修改?
谢谢!!
------解决方案--------------------》》》
// document.forms(0).item( ' " + this.ClientID + ": " + this.DDL1.ID + " ') 已经返回一个对象还那么费劲 getElementById 做什么 ???
if ( getDDL1().selectedIndex > getDDL2().selectedIndex )
// OR
if ( document.getElementByID( ' <% =DDL1.ClientID %> ').selectedIndex >
document.getElementByID( ' <% =DDL2.ClientID %> ').SelectedIndex )