asp.net - jQuery Validation - Using validation on click, not on submit - Stack Overflow

I'm using (or trying to) JQuery Validation with WebFormshtml.I have, basically (simplifying the r

I'm using (or trying to) JQuery Validation with WebForms/html.

I have, basically (simplifying the real html, showing only the elements):

<input id="txtEmail"/>
<input id="txtTicketID"/>
<a id="create" href="#">Create a new ticket</a>
<a id="find" href="#">Find this ticket</a>

The javascript for validation/action is here:

$(function() {
    $("#aspnetForm").validate({
        rules: {
            txtEmail: {
                required: true,
                email: true
                ,
                messages: {
                    required: "* enter your e-mail",
                    email: "*  invalid e-mail"
                }
            },
            txtTicketID: {
                required: true,
                digits: true,
                messages: {
                    required: "*",
                    digits: "* invalid ticket"
                }
            }
        },
        onfocusout: true,
        onkeyup: true,
        onsubmit: false,
        debug: true
    });

    $("#create").click(function() {
        if ($("#aspnetForm").valid()) {
            var email = $("#txtEmail").val();
            if (email != "")
                window.location = "CreateTicket.aspx?email=" + email;
        }
    });

    $("#find").click(function() {
        if ($("#aspnetForm").valid()) {
            var email = $("#txtEmail").val();
            var ticketID = $("#txtTicketID").val();
            if (email != "" && ticketID != "")
                window.location = "DetailEditTicket.aspx?email=" + email + "&ticketID=" + ticketID;
        }
    });
});

It is not working at all.. the valid() on the links click always return true, even if the fields are blank, or wrong.

When I type something, blur, etc, nothing makes validation happen.

Do you see what is missing on this?

I'm using (or trying to) JQuery Validation with WebForms/html.

I have, basically (simplifying the real html, showing only the elements):

<input id="txtEmail"/>
<input id="txtTicketID"/>
<a id="create" href="#">Create a new ticket</a>
<a id="find" href="#">Find this ticket</a>

The javascript for validation/action is here:

$(function() {
    $("#aspnetForm").validate({
        rules: {
            txtEmail: {
                required: true,
                email: true
                ,
                messages: {
                    required: "* enter your e-mail",
                    email: "*  invalid e-mail"
                }
            },
            txtTicketID: {
                required: true,
                digits: true,
                messages: {
                    required: "*",
                    digits: "* invalid ticket"
                }
            }
        },
        onfocusout: true,
        onkeyup: true,
        onsubmit: false,
        debug: true
    });

    $("#create").click(function() {
        if ($("#aspnetForm").valid()) {
            var email = $("#txtEmail").val();
            if (email != "")
                window.location = "CreateTicket.aspx?email=" + email;
        }
    });

    $("#find").click(function() {
        if ($("#aspnetForm").valid()) {
            var email = $("#txtEmail").val();
            var ticketID = $("#txtTicketID").val();
            if (email != "" && ticketID != "")
                window.location = "DetailEditTicket.aspx?email=" + email + "&ticketID=" + ticketID;
        }
    });
});

It is not working at all.. the valid() on the links click always return true, even if the fields are blank, or wrong.

When I type something, blur, etc, nothing makes validation happen.

Do you see what is missing on this?

Share Improve this question asked Aug 27, 2009 at 14:19 Victor RodriguesVictor Rodrigues 11.8k25 gold badges78 silver badges108 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

the validate(rules:{}) takes options consisting of a name:{object} pattern, you're passing in an id:{object} pattern. Try:

<input id="txtEmail" name="txtEmail"/>
<input id="txtTicketID" name="txtTicketID"/>
<a id="create" href="#">Create a new ticket</a>
<a id="find" href="#">Find this ticket</a>

You may have missed some code out but it looks like you're calling the function 'valid' but you've set it as 'validate'. So your function for validating emails and ticket ID's isn't running at all.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742414945a4439558.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信