1

I'm new to JQuery and I'm writing code to check a registration form. Here's my label in the server page:

<asp:Label ID="LabelErrorFirstName" runat="server" ForeColor="Red" Font-Size="Small"></asp:Label>

and my JQuery script:

if(firstnameTxt.length == '') {
      $('#<%= LabelErrorFirstName.ClientID %>').text("Please enter a first name.");

  }  

I access this script from the OnClientClick event in a button on the form which I know works i.e. I set alerts here which shows it's getting there. I've commented out the 'if' statement in case that was the problem but it isn't.

What I want to happen is to have this label's text property set if the first name textbox is empty to "Please enter.." etc. I've tried many variations but I can't get it.

What am I missing?

Paul

1
  • 1
    Did you tried a RequiredFieldValidator control? Commented Jan 17, 2013 at 21:46

1 Answer 1

1

Length is an integer not a string.

if(firstnameTxt.length == 0) {
    $('#<%= LabelErrorFirstName.ClientID %>').text("Please enter a first name.");
} 

Also, make sure your label is being found by jquery:

if( $("#<%= LabelErrorFirstName.ClientID %>").length > 0 ) {
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, length does return an integer but, as I said in my post, "I've commented out the 'if' statement in case that was the problem but it isn't."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.