Question

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...

Was it helpful?

Solution

try txtUser.ClientID instead of UniqueID

OTHER TIPS

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

Note the # that's missing as well.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top