請求書フォームと jquery 関数があります。請求書で、利用可能な数量を超える数量を入力すると、ユーザーに警告する必要があります。
私の問題は次のとおりです。最大数量を 5 にします。データを 7 (1 桁 > 最大利用可能数量) として入力すると、コードは正常に動作します。しかし、2つのデジギスト番号を入力すると、たとえば. 17 (2 桁 > 最大利用可能数量) の場合、アラート ボックスが表示されません。onkeyup というのは、関数が 1 桁でしか機能していないということです。
どうすればそれを実現できますか?助けてください。
$('input[name="quantity"]').keyup(function()
{
//problem is here
var $tr = $(this).closest("tr");
var unitprice = $tr.find('input[name^="unitprice"]').val();
var q = $tr.find('input[name^="quantity"]').val();
var cq = $tr.find('input[name^="checkquantity"]').val();
if(q>cq)
{
alert("Error: Quantity value exceeds then available quantity..Max Quantity is "+cq);
//this works fine only if single digit is entered in textbox quantity
}
//----below are some other stuffs -these are working fine
$tr.find('input[name^="sprice"]').val($(this).val() * unitprice);
var totalPrice = 0;
$('input[name="sprice"]').each(function()
{
totalPrice += parseFloat(this.value);
$('[name=subtotal]').val(totalPrice);
});
});
--------------
------------
// Form containing the above textboxes
<input type="submit" id="submitbtnId" value="Save"/>`