如何使用JavaScript在while循环中检索文本字段的值?

Inside the while loop there are text boxes. There is JavaScript function called checkNum() which is use to retrieve the text box value but i don't get it how to do that?

<script>
function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : evt.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       }
       
function checkNum()
{
    var num = document.getElementById('num');
    
}
</script>
<table width="506" border="0">
  <tr>
    <td width="189" align="center">Text One</td>
    
  </tr>
  <?php
  $i =0;
  $data = "select * from tbl_person";
  $query = mysqli_query($conn,$data);
  while($row = mysqli_fetch_array($query))
  {
      $i++;
  ?>
  <tr>
    <td align="center"><input type="text" name="num<?php echo $i;?>" id="num<?php echo $i;?>" onkeypress="return isNumberKey(event)"/></td>
    
  </tr>
  <?php
  }
  ?>
  
</table>

</div>
    function loopTexts(numRows)
    {
      for(var i = 1; i <= numRows; i++)
      {
        var txt = document.getElementById('txt'+i);
        var str = txt.value;
        alert(str);
      }
    }


<?php
//Some query here
    $numRows = mysqli_num_rows($resultSet);
//Loop through the result set and create the fields as you did
?>

    <input type="text" value="text1" id="txt1"/>
    <input type="text" value="text2" id="txt2"/>
    <input type="text" value="text3" id="txt3"/>
    <input type="text" value="text4" id="txt4"/>
    <input type="text" value="text5" id="txt5"/>
//echo the parameter $numRows to pass it to the JS function
    <input type="button" value="Loop!" onclick=<?php echo "loopTexts($numRows);"; ?>/>

If you don't know how many text boxes will be created during runtime, pass it as an argument to the javascript function and use it in the for loop.

Call the function in whatever event you are supposed to use it.

Have the function accept the input as a parameter:

function checkNum(input)
{
    var num = input.value;

}

Then add the onblur attribute to the field, and pass this as a parameter:

<input type="text" onblur="checkNum(this)" name="num<?php echo $i;?>" id="num<?php echo $i;?>" onkeypress="return isNumberKey(event)"/>