I have 4 input fields that allow the user to enter the value (rating) of these 4 companies in a specific Area, as shown below:
<table> <tr><th></th><th>Area 1</th></tr> <tr><td>Company A</td><td><input type="text" name="text1" id="text1"></td></tr> <tr><td>Company B</td><td><input type="text" name="text2" id="text2"></td></tr> <tr><td>Company C</td><td><input type="text" name="text3" id="text3"></td></tr> <tr><td>Company D</td><td><input type="text" name="text4" id="text4"></td></tr> </table>
Input fields are not required and must be integers from 1 to 4 (suppose there are no duplicates),
the user cannot jump in the rating, which means that the rating must be unique and continuous.
For example, * We can enter 1 , 3 , 2 , as well as 4 , 2 , 1 , 3 .
But when the input is like 3 , 1 , then we need to warn 2 .
When we enter 3 , we need to warn 1 and 2 as missing.
Here is my code to check the rating:
function checkMissingRank(object){ object.change(function() { var max = 0; var actSum = 0; var rows = object.length; for(var i=1 ; i<=rows ; i++){ if($('#text'+i+'').val() != ""){ var actVal = parseInt($('#text'+i+'').val());
It works great when only one value is missing, but when 2 values ββare missing ( 1 , 2 ), it simply returns the sum (3) of them. How can I improve this?
javascript jquery html
user3368506
source share