How to make a JavaScript function to change the checked status of radio input rows on click of button?

I have timesheet project in which each row of table represent employee timesheet entry and values of each row are seen by the admin and are marked either status = 1 or 2 or 3. I want to make a button which on click run a javascript function to change the status of all row (let's initially the status of all entry is 1 and on click of the button some javascript code may change all entry status to 2).

You get more clear on seeing pic.

Timesheet

Inspected pic 1

Inspected pic 2

I tried to simplify the problem as below in code.

<!DOCTYPE html>
<html>
<body>

<table border=1>
<tr></tr>
<tr></tr>
<tr>

<td><input type='radio' name=row_1[] value='1' checked></td>
<td><input type='radio' name=row_1[] value='2' ></td>
<td><input type='radio' name=row_1[] value='3' ></td>
</tr>

<tr>

<td><input type='radio' name=row_2[] value='1' checked></td>
<td><input type='radio' name=row_2[] value='2' ></td>
<td><input type='radio' name=row_2[] value='3' ></td>
</tr>

<tr>

<td><input type='radio' name=row_3[] value='1' checked></td>
<td><input type='radio' name=row_3[] value='2' ></td>
<td><input type='radio' name=row_3[] value='3' ></td>
</tr>

<tr></tr>
<tr></tr>

</table>

<br><br>

<button onclick="backwardclick();">backward</button>
<button onclick="forwardclick();">forward</button>


<script>
function forwardclick() {
    var divs = document.querySelectorAll("tr");

    document.write(divs);

    for (var x = 0; x < divs.length; x++) {

      if (x>=2) {
      var row1 = divs[x].querySelectorAll("input[type=radio]")

        for (var i = 0; i < row1.length; i++) {
            if (row1[i].checked) {
                row1[i].checked = false;
                row1[(i + 1) % row1.length].checked = true;
                break;
            } // end if
        } // end for
    } // end for

    }

  } // end function

  function backwardclick() {
      var divs = document.querySelectorAll("tr");
      for (var x = 0; x < divs.length; x++) {
          var row1 = divs[x].querySelectorAll("input[type=radio]")
          for (var i = 0; i < row1.length; i++) {
              if (row1[i].checked) {
                  row1[i].checked = false;
                  row1[(i - 1 + row1.length) % row1.length].checked = true;
                  break;
              } // end if
          } //end for
      } //end for
  } // end function
</script>

</body>
</html>

outpupt of above code

when the user clicks on forward button all rows with radio option is checked to next available radio and when the user click on backward button it get the previous radio checked as available. I am not able to get through the java script function.

Now my code starts.

Code for below file in which i need to add some javascript- admindashboardentry.php. This below code consist of if condition which match the case and display the rows.

elseif (isset($_POST['showBillablePlusNotInvoicedEntry']))
{

    echo "<p>Billable + Not Invoiced Entries</p>";            
    include('connection.php');          
    echo "<form action = 'download.php' method = 'post'>";
    echo "<input type ='hidden' name='status' value= '2' >";
    echo "<button type='submit' name = 'statusentrydownload' class='btn btn-outline-primary' style='float:left;'><i class='fa fa-download' style='margin-right:10px;'></i>Download</button>";
    echo "</form>";
    echo "<button onclick='window.location.reload(true);' class='btn btn-outline-secondary' style='margin-left:10px; border-radius: 3px;  height:20px;'><i class='fa fa-refresh' style='margin-right:10px;'></i>Refresh</button>";
    echo "<br>"; echo "<br>";                       
    echo "<span><b>*NB - Not Billable, *B+NI - Billable + Not Invoiced, *B+I - Billable + Invoiced</b></span>";
    echo "<span style='margin-left:10px;'><b><img src='./images/grey.png' alt='' style='width:25px;height:25px;'> Not Seen Entries&nbsp&nbsp<img src='./images/blue1.png' alt='' style='width:25px;height:25px;'> Billable + Not Invoiced Entries &nbsp&nbsp <img src='./images/green.png' alt='' style='width:25px;height:25px;'> Billable + Invoiced Entries</b></span>";

    //-------------------------------------------------

    echo "<br>";
    // some button which change all the state of the rows
    echo "Change status: ";
    echo "<button onclick='' class='btn btn-outline-secondary' style='border-radius: 3px;  margin-left:5px; '><i class='fa fa-backward' style='margin-right:10px;'></i>Previous</button>";
    echo "<button onclick='' class='btn btn-outline-secondary' style='border-radius: 3px; margin-left:10px; '><i class='fa fa-forward' style='margin-right:10px;'></i>Next</button>";
    echo "<br>";
    //This above button will the change the radio button status forward button 2 -> 3 and backward button 1 <- 2

    //--------------------------------------------------

    $filename = './text/empid.txt';                               
    $fp = @fopen($filename, 'r') or die('Unable to open file!');                                
    if ($fp) {
        $empid_array = explode(PHP_EOL, fread($fp, filesize($filename)));
    }

    //to remove empty spaces
    $empid_array = array_filter($empid_array);
    $empid_array = array_unique($empid_array);
    sort($empid_array);                         
    $sumNoOfHours = 0.0;                                
    displayTableHeading();                          
    $i=1;                                                           

    foreach ($empid_array as $code) {
      //split the $code variable to get the emp id 
      $codearr = explode(" - ", $code);
      $empid = $codearr[0];
      $selectSql = "SELECT * FROM `mastertbl` WHERE EmpID = '$empid' AND Status = 2 ORDER BY Date DESC, ModifiedDate DESC";
      $result = mysqli_query($conn, $selectSql) or die( mysqli_error($conn));                             
        while($row = mysqli_fetch_array($result))
      {
        $sumNoOfHours = $sumNoOfHours + $row['NoOfHours'];
        displayTableRow($row, $i, $empid);
        $i++;                                   
      }
    }                           
    echo "
      <tr>
          <td colspan=10>&nbsp;</td>
          <td><button type='submit' class='btn btn-outline-primary'  style='border-radius: 3px;'><i class='fas fa-edit' style='margin-right:10px;'></i>Update</button></td>
      </tr>
      </table>";
    echo "</form>";
    tableEnding($sumNoOfHours);
    echo "<br>";
}

and this function displayTableRow($row, $i, $empid) which displays the row of table as in picture. as below code. (only name variable of tag is there in each row).

// Webpage Table Row
    function displayTableRow($row, $i, $empid) {
        $notBillable = intval( $row['Status'] )==1 ? 'checked' : '';
        $billablePlusNotInvoiced = intval( $row['Status'] )==2 ? 'checked' : '';
        $billablePlusInvoiced = intval( $row['Status'] )==3 ? 'checked' : '';

    // IF Condition to check the radio button are not selected by admin starts

    if (empty($notBillable) && empty($billablePlusNotInvoiced) && empty($billablePlusInvoiced)) {

        if ($row['WorkFromHome'] == 1) {

          printf("
            <!-- record: %d -->
            <tr>
              <td><input type='text' size='10' name='empid[]' value='%s' style = 'background-color: #D3D3D3;' readonly/></td>
              <td><input type='text' size='7' name='date[]' value='%s' style = 'background-color: #D3D3D3;'/></td>
              <td><input type='text' size='5' name='stime[]' value='%s' style = 'background-color: #D3D3D3;'/></td>
              <td><input type='text' size='5' name='etime[]' value='%s' style = 'background-color: #D3D3D3;'/></td>
              <td><input type='text' size='1' name='hours[]' value='%s' style = 'background-color: #D3D3D3;'/></td>
              <td><b><input type='text' size='9' name='projectcode[]' value='%s' style = 'background-color: #D3D3D3;' /></b></td>
              <td><input type='text' size='30' name='taskperformed[]' value='%s' style = 'background-color: #D3D3D3;' /></td>

              <td><input type='text' size='8' name='invoicenum[]' value='%s' style = 'background-color: #D3D3D3;' /></td>
              <td><input type='radio' name='status_{$i}[]' value='1' %s/>NB</td>
              <td><input type='radio' name='status_{$i}[]' value='2' %s/>B+NI</td>
              <td><input type='radio' name='status_{$i}[]' value='3' %s/>B+I</td>
              <input type='hidden' name='modifieddate[]' value='%s'>
            </tr>",
            $i,
            getEmpNameById($empid),
            $row['Date'],
            $row['StartTime'],
            $row['EndTime'],
            $row['NoOfHours'],
            $row['ProjectCode'],
            $row['TaskPerformed'],

            $row['InvoiceNumber'],
            $notBillable,
            $billablePlusNotInvoiced,
            $billablePlusInvoiced,
            $row['ModifiedDate']
            );

        }else{
          printf("
            <!-- record: %d -->
            <tr>
              <td><input type='text' size='10' name='empid[]' value='%s' style = 'background-color: #D3D3D3;' readonly/></td>
              <td><input type='text' size='7' name='date[]' value='%s' style = 'background-color: #D3D3D3;'/></td>
              <td><input type='text' size='5' name='stime[]' value='%s' style = 'background-color: #D3D3D3;'/></td>
              <td><input type='text' size='5' name='etime[]' value='%s' style = 'background-color: #D3D3D3;'/></td>
              <td><input type='text' size='1' name='hours[]' value='%s' style = 'background-color: #D3D3D3;'/></td>
              <td><b><input type='text' size='9' name='projectcode[]' value='%s' style = 'background-color: #D3D3D3;' /></b></td>
              <td><input type='text' size='30' name='taskperformed[]' value='%s' style = 'background-color: #D3D3D3;' /></td>

              <td><input type='text' size='8' name='invoicenum[]' value='%s' style = 'background-color: #D3D3D3;' /></td>
              <td><input type='radio' name='status_{$i}[]' value='1' %s/>NB</td>
              <td><input type='radio' name='status_{$i}[]' value='2' %s/>B+NI</td>
              <td><input type='radio' name='status_{$i}[]' value='3' %s/>B+I</td>
              <input type='hidden' name='modifieddate[]' value='%s'>

            </tr>",
            $i,
            getEmpNameById($empid),
            $row['Date'],
            $row['StartTime'],
            $row['EndTime'],
            $row['NoOfHours'],
            $row['ProjectCode'],
            $row['TaskPerformed'],

            $row['InvoiceNumber'],
            $notBillable,
            $billablePlusNotInvoiced,
            $billablePlusInvoiced,
            $row['ModifiedDate']
            );
        }
    }
    // IF Condition to check the radio button are not selected by admin end

Each time new row is fetched from database this below code changes,

<td><input type="radio" name="status_1[]" value="1" checked="">NB</td>

Please help.