开发者

Jquery Multiple events for form submit not waiting

I have to check unique email ids in my project. for that i am using json and returning the value. it works fine. the code is

$(document).ready(function() {
        // Add the page method call as an onblur handler for the email textbox.
        $("#<%= txtPrimEmail.ClientID %>").blur(function() {
            $.ajax({
                type: "POST",
                url: "customerEmail.asmx/CheckCustEmail",
                data: "{mailId: '" + $("#<%= txtPrimEmail.ClientID %>").val() + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    if (msg.d != "0") {
                        // Replace the div's content with the page method's return.
                        document.getElementById('pm').value = "1";
                        $("#duplicate").text('This email has already been taken');
                        var myInputOffset = $('#<%= txtPrimEmail.ClientID %>').offset(); // Get the position of the input field relative to the document
                        $('#duplicate').css({ 'top': myInputOffset.top + 25, 'left': myInputOffset.left + 100, 'visibility': 'visible' }); // Position the div
                        $("#<%= txtPrimEmail.ClientID %>").removeClass().addClass("ErrorTxt");
                    }
                    else {
                        $("#<%= txtPrimEmail.ClientID %>").removeClass().addClass("textbox");
                        $("#duplicate").text('');
                        $('#duplicate').css('visibility', 'hidden');
                    }
                }
            });
        });

I am doing the same for secondary email text box also.

the pbm is, If i type on the textbox and click outside the textbox, and then hit the submit button,... the fu开发者_JAVA技巧nction is working fine. But It is not working if i type on the textbox and without clicking outside the textbox , i hit submit button - the function not firing. So i have called the same function in form submit also:

 $('form').submit(function() {
            $("#<%= txtPrimEmail.ClientID %>").trigger('blur');
        });

        $('form').submit(function() {
            $("#<%= txtSecEmail.ClientID %>").trigger('blur');
        });

        $('form').submit(function() {
            var pOk = document.getElementById('pm').value;
            var sOk = document.getElementById('sm').value;
           //here i am checking email errors and returning false;
            //return false;

        });

the problem now is, before the error div displays, it calls the last submit event...i have tried using callback also.. not seems to work...

Sorry for posting such a long question... Anyone please help.....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜