0

入力を金額として受け取るテキストボックスがあります..ユーザーが特定の金額を超える金額を入力できないようにしたい..ajaxを使用してみました..しかし、思い通りに機能しません..jquery wudは必要です..しかし、私はそれがあまり得意ではありません..誰かが助けることができれば?? 私が書いたAjax関数:

function maxIssue(max, input, iid) {
    var req = getXMLHTTP();
    var strURL = "limit_input.php?max=" + max + "&iid=" + iid;
    if (input > max) {
        alert("Issue Failed.Quantity Present in Stock is " + max);
    }

    if (input < 0) {
        alert("Issue Failed.Enter positive Value");
    }

    if (req) {
        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                // only if "OK"
                if (req.status == 200) {
                    document.getElementById('maxdiv').innerHTML = req.responseText;
                } else {
                    alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                }
            }
        }
    }
    req.open("GET", strURL, true);
    req.send(null);
}
4

4 に答える 4

1
$('input').on('keyup', function(){
    if($(this).val() > someNumber){
        $(this).prop('disabled', true);
        alert('You cannot enter that many characters.');
    }
}); 
于 2012-12-18T04:30:08.660 に答える
1

使ってみましたmaxLengthか?

<input maxLength="10"/>
于 2012-12-18T04:31:29.600 に答える
0

jquery 検証の使用は非常に簡単です。検証のために表示するルールとメッセージを定義し、それをフォーム要素に添付する必要があります。

このチュートリアルは非常に役立ちます。

http://www.codeproject.com/Articles/213138/An-Example-to-Use-jQuery-Validation-Plugin

試してみたい場合に備えて、検証に関する 101 を次に示します。私は cdn を使用していますが、パスにライブラリへの参照を追加できます。

<html>
<head>
<title>Validation Test</title>
<!-- Importing jquery and jquery ui library from cdn -->

<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.js"></script>

<!-- End of Import -->

</head>
<body>

<script>
  $(document).ready(function(){
    $("#testvalidation").validate({

      rules: {
          title: "required",
          description: {
            required:true,
            maxlength:4000
        }
      },
    messages: {
      title: "Title is Required",
      description: {
          required : "Description is Required",
          maxlength: "Should be less than 4000 Characters"
      }
    }
   });
  });
  </script>

  <style>

    #testvalidation .error{
    color: #FB3A3A;
    font-weight:300;

} 

</style>

  <form action=update.jsp class="form-horizontal" id="testvalidation">

  <input name="title" type="text"></input><br>
  <textarea name="description"></textarea>
  <input type="submit" value="Submit">

  </form>
</body>
</html>
于 2012-12-18T05:38:24.260 に答える
0

それはあなたの仕事に役立ちます。

<input type="text" name="usrname" maxlength="10" />

function limitText(field, maxChar){
    $(field).attr('maxlength',maxChar);
}
于 2012-12-18T05:01:08.153 に答える