I have a label on a ASP.Net 4.0 website which I'm trying to hide when the users types into a textbox.
I have a Javascript function which I'm firing on the Keypressevent of a Textbox.
So, my Javascript function is:
function hideLabel(sender, e) {
document.getElementById('<%=lblResult.ClientID%>').style.display = 'none';
}
And my textbox and labels are as follows:
<tr><td>
<asp:Label ID="lblResult" runat="server" Visible="True"></asp:Label>
</td></td>
<tr><td>
<asp:TextBox ID="txtEmailAddress" runat="server" Width="200px"
CssClass="customtxt" onkeypress="hideLabel(this, event)"></asp:TextBox>
</td></td>
The function fires but I receive the following error: Microsoft JScript runtime error: Object required
I've also tried the below line of code within my function but this doesn't work either:
document.getElementById('lblResult').style.visibility = 'hidden';
Anybody got any idea why this is failing in IE 8 - it is working correctly in Chrome.
<span id="MainContent_lblResult">Text here</span>- which may not be what you intended - you should set theAssociatedControlIDto the ID of the text box if you want a<label>instead. 2) Have you tried opening the IE Developer Tools (F12) and checked the Console for errors? The code as you have it should work, and I've tested a similar set up (albeit with IE9 in IE8 mode).