0

誰かが私が次のことを達成できる方法を知っていますか?

ユーザーが入力ボックスに1を入力すると、アラートがポップアップ表示されますが、ユーザーが新しい値を確認して入力フィールドに最小値を自動的に入力するか、キャンセルしてフィールドを空白のままにすることができるようにしたいと思います。

私はこれまでに次のコードを持っています:

function Form_Validator(theForm)
{
    var err = false;
    var field;
    var msg = 'Please correct the following to continue...\n';
    var alpha = /\w/;
    var numeric = /[^0-9^\s]/;
    var emailvalidator = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;

    var teststr = '';


        if(theForm.prod_quantity.value == '1'){
        msg += '\nThe minimum order amount is 2.';
        if (!err){
            field = theForm.prod_quantity;
            err = true;
        }
    }

        if (!err){
        return true;
    }
    else{
        alert(msg);
        field.focus();
        return false;
    }
}


<b>Quantity:</b> <input type="text" class="prod_quantity" name="prod_quantity"  />
<input type="submit" value="" class="add-basket-btn"/>

アラートボックスを表示することができましたが、[OK]をクリックすると値が2になるように自動入力する方法がわかりません。これが理にかなっていることを願っています。

4

2 に答える 2

0

条件の代わりに単純なconfirm()ダイアログを使用alert()し、入力ボックスに目的の値を設定します。

if (confirm (msg)) {  // ask for confirmation
   // set the new value 
   theForm.prod_quantity.value = 2;
} else {
   // leave the box blank
   theForm.prod_quantity.value = '';
}
​
于 2012-09-05T16:37:49.060 に答える
0
// ...
var orderAmount = confirm(msg);
if ( orderAmount ) theForm.prod_quantity.value = "2";
于 2012-09-05T16:38:35.763 に答える