Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

The Jquery code below works very well and checks for input values based on conditions .. But for the ESNList text field in the HTML form , many ESNs(numbers) can be entered and separated by a comma in the same text field , how can I make so Jquery makes sure that all the numbers entered on the same text field still match the condition for ESNList , your help would be greatly appreciated ..

 <html>
    <head>
    <script type="text/javascript" src="jquery/jquery-1.8.3.js"></script>
    <script type="text/javascript">

    $(function () {


    $(":text").css("border", "2px solid red");
      $(":text").keyup(function(){
        var enteredData = $(this).val()
        console.log(enteredData);
        if (enteredData == "") {
          $(this).css("border", "2px solid red");
        } else {
          $(this).css("border", "inherit");
        }
        if ($(this).attr("id") == "ESNList"){
          esnList = parseInt(enteredData);
          switch (true){
            case ( esnList >= 986329 && esnList <= 999999):
                $("#ddl_StxName").val("stx2");
                $("#ddl_rtumodel").val("globalstar");
                break;
            case ( esnList >= 660000 && esnList <= 699999):
                $("#ddl_StxName").val("mmt");
                $("#ddl_rtumodel").val("globalstar");
                break;
            case ( esnList >= 200000 && esnList <= 299999):
                $("#ddl_StxName").val("stm3");
                $("#ddl_rtumodel").val("stmcomtech");
                break;
            case ( esnList >= 1202114 && esnList <= 1299999):
                $("#ddl_StxName").val("smartone");
                $("#ddl_rtumodel").val("globalstar");
                break;
          }

        }
      });
      });
    </script> </head>
    <body>
    <form id="provision">
        ESNList:    <input  type="text" id="ESNList" name="ESNList" size="30" /> <br />
        ESN Start:<input type="text" id="ESNStart" name="ESNStart" size="10" /> <br />
        ESN End: <input type="text" id="ESNStart" name="ESNStart" size="10" /> <br />
        UnitName:<input type="text" id="STxName" name="STxName" size="30"  />  <br />  
         Unit Model:   <select name="STxName" id="ddl_StxName">
        <option value="stx2">STX2</option>
        <option value="stm3" selected>STM3</option>
        <option value="acutec">Acutec</option>
         <option value="trackpack">Trackpack</option>
        <option value="mmt">MMT</option>
        <option value="smartone">Smartone</option>
        <option value="smartoneb" >SmartOneB</option>
        </select> <br />
        RTU Model Type:
         <select name="rtumodel" id ="ddl_rtumodel">
        <option value="globalstar">GlobalStar</option>
        <option value="both">Both</option>
        <option value="comtech">Comtech</option>
        <option value="stmcomtech">STMComtech</option>
        </select> <br />
        <input type="submit" value ="submit"  />
        </form>
    </body>
    </html> 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
287 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can split the list by a comma delimiter and validate each individual element.

$.each(enteredData.split(","), function(i, str){
    var esnList = +str;
    /* enter validation here */
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...