javascript - How to validate multiple inputs with different values -


i'm trying validate example 6 inputs (i can create more 100) these inputs created dynamically, problem here example the first 2 input values must between 0 , 10, other 2 between 5 , 10 , last 2 inputs between 3 , 5. validate if said can create more 100 inputs means lot of code, here have:

$(document).ready(function () {    $('#create').change(function () {      draw();    });        $('#btn').click(function () {      validate();    });  });    function draw() {    var total = $('#create').val();    var html = "";    (var x = 0; x < total; x++) {      html += '<input id="inputnum' + x + '" />';    }    $('#draw').html(html);  }    function validate() {    var input1 = $('#inputnum0').val();    var input2 = $('#inputnum1').val();    var input3 = $('#inputnum2').val();    var input4 = $('#inputnum3').val();        if (input1 < 5 && input1 >0 && input2 < 5 && input2 > 0)      alert("hello");    else      alert("value must between 0-5");        if (input3 < 15 && input3 > 5 && input4 < 15 && input4 > 5 )      alert("hello");    else      alert("value must between 5-15");      }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>      <select id="create">    <option selected disabled>choose</option>    <option>6</option>  <select />        <div id="draw">    </div>        <button id="btn">valida</button>

i want know if exists simple way instead using if every input want check?

use eq() function.

$("input").eq(-2) // before last element $("input").eq(-1) // last element 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -