0

フォームにリピーターがあり、jqueryを使用してリピーターのデータを検証しました。jqueryを使用してクライアント側でページがリダイレクトされないようにするのに問題があります。

これが私のjqueryです:

function ValidateBid() 
{
    $(document).ready(function () {

        $(".btnSubmitBid").click(function (evt) {

            var msg = "";
            var bid = $(this).closest('td').find("input"); //this was the fun part

            if (isNaN(bid.val())) {
                msg = "Bid amount allowed in complete dollars only";
            }
            if (bid.val().indexOf('.') >= 0) {
                msg = "Bid amount may only contain numbers";
            }
            if (bid.val() > 999999) {
                msg = "If you want to place a bid for $" + bid.val() + " please contact customer service";
            }

            if (msg.length > 0) {

                $('#dialogText').text(msg);
                $('#dialog').dialog({
                    closeOnEscape: true, modal: true, width: 450, height: 200, title: 'Please correct the errors below:', close: function (event, ui) { $(this).dialog("destroy"); }
                });
                evt.preventDefault();
                return false;
            }
            else {
                return true;
            }

        });
    });

} //ends doc rdy

return falseとevt.preventDefault();を使用してみました。運がない。

ユーザーがまだログインしていない場合は、repeater_ItemCommandイベントのコードビハインドでリダイレクトされます。

どんな助けでも大歓迎です。ありがとう。

4

1 に答える 1

2

関数内で document.ready を呼び出すことはお勧めできません。送信ボタンのクリックイベントにバインドしています。関数ラッパーを削除し、フォーム自体の送信イベントにバインドします。そのようにして、検証でエラーが見つかったときに false を返すだけで、そうでない場合は続行しますサブミッションでは、必要を感じた場合に return true が害を及ぼすことはありません。

$(document).ready(function () {

        $("form").submit(function (evt) {
//obv you would need to put the form id or class if you have more than one form on the page

            var msg = "";
            var bid = $(this).closest('td').find("input"); //this was the fun part

            if (isNaN(bid.val())) {
                msg = "Bid amount allowed in complete dollars only";
            }
            if (bid.val().indexOf('.') >= 0) {
                msg = "Bid amount may only contain numbers";
            }
            if (bid.val() > 999999) {
                msg = "If you want to place a bid for $" + bid.val() + " please contact customer service";
            }

            if (msg.length > 0) {

                $('#dialogText').text(msg);
                $('#dialog').dialog({
                    closeOnEscape: true, modal: true, width: 450, height: 200, title: 'Please correct the errors below:', close: function (event, ui) { $(this).dialog("destroy"); }
                });

                return false;
            }
            else {
                return true;
            }

        });
    });
于 2012-08-12T21:56:33.750 に答える