Editing a labels text value through JavaScript in VB ASP.NET

Posted by Ronnie on Stack Overflow See other posts from Stack Overflow or by Ronnie
Published on 2010-03-22T01:00:16Z Indexed on 2010/03/22 1:11 UTC
Read the original article Hit count: 432

Filed under:
|
|
|

I have a simple form containing two text boxes, I am attempting to apply some validation to the first text box using JavaScript. This is the first time I have attempted this and am having some trouble.

I have a label beside the text box stating an error, this labels visibility property is set to False. I wish the labels visibility to turn true if the text box is empty when the user loses focus.

For this I have used the onBlur option within the tags of the text box. It then calls the JavaScript function and should set the label to Visible but it does not. I have tested to see if it is entering the function by using an alert instead and that works. The problem seems to be trying to alter the visibility property of the label.

Here is the portion of my code:

The JavaScript:

function myRegEx(frm) {

    if ( boxUsername.value == "" ) {

        invalidUser.visible = True;
        return false;

    }
}    

The form:

<asp:TextBox onblur="return myRegEx(this)" id="boxUsername" runat="server" Width="200px"></asp:TextBox>

<asp:Label id="invalidUser" runat="server" visible="False" forecolor="Red" text="* Username must be alphanumeric with no special characters"></asp:Label>

Any help would be brilliant.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about vb