我写了一个简单的javascript函数来验证apx页面中的文本框
<body>
<script type="text/javascript" >
function checkTextbox(sender, target) {
if (document.getElementById(sender).value < document.getElementById(target).value) {
var lbl = document.getElementById('<%=lbl_Outlet_Message.ClientID %>');
lbl.style.display = 'block';
lbl.value = "Enter Slab To Value should be greater or equals to From Value ";
}
}
</script>
<form id="form1" runat="server">
<asp:Label ID="lbl_Outlet_Message" runat="server" ForeColor="Red" Visible="False"></asp:Label>
<asp:TextBox ID="txt_from_02" runat="server" ></asp:TextBox>
<asp:TextBox ID="txt_to_02" runat="server" onKeyUp="checkTextbox(this,'txt_from_02')">
</asp:TextBox>
</form>
</body>
当我运行aspx页面时,出现以下错误
“ 0x800a01a8-Microsoft JScript运行时错误:必需对象”
我不知道哪里出了问题。
最佳答案
函数checkTextbox
期望发送者为id,但是您要使用this
传递当前对象,则应使用this.id
而不是this
或通过直接评估当前对象的value属性来更改if条件,而不是传递当前对象到document.getElementById
更改
if (document.getElementById(sender).value
至
if (sender.value