views:

197

answers:

3

i try to customize the rule of the JQuery validation plugin and I'm almost done. The only problem I got is that the function $("<%=txtUserl.UniqueID %>").val() return undefined. How can I get the value of that textbox ?

$("#aspnetForm").validate
(
    {
        rules:
        {
            <%=txtUser.UniqueID %>: 
            {
                required: true,
                remote: "CheckUser.aspx?User=" + $("#<%=txtUser.ClientID %>").val()
            }
        },
        messages:
        {
            <%=txtUser.UniqueID %>: 
            {
                remote: "Invalid user"
            }
        }
    }
);

And in my webform

<asp:TextBox ID="txtUser" runat="server" TabIndex="1" />

UPDATE

I change to use ClientID instead of UniqueID. Also, I put my javascript code at the end of my file instead of in the beginning of the file.

Now, the problem I got is txtUser.val() return an empty string "". in fact, I notice that it's return the old value of the textbox if I change the value. It's doesn't return the current value, which is want I need...

+2  A: 

try txtUser.ClientID instead of UniqueID

Gordon Tucker
Correct, ID = ClientID, used in $("#ID"), name = UniqueID which is what validation uses for rules, like you have in messages.
Nick Craver
A: 
$("#<%=txtUser.ClientID %>").val()

Note the # that's missing as well.

Nick Craver
A: 

Yes use the txtUser.ClientID but also you have to use the (#) to get the value of the text box your statement should be

$("#"+"<%=txtUser.UniqueID %>").val()

if you don't use (#) sign then it will give error hope this will help

Asim Sajjad