刷新页面时,表格单元格突出显示的行的颜色正在改变

I have a table which change the color of the row of table cell when an option has been selected. But when I refresh the page, the color changes back to the default color. What can I do to fix the highlighted color in the table?

Here is the code for my php and mysql table:

<?php

    while ($record = mysqli_fetch_array($result)) {

      echo"<tr>";
      echo"<td style='text-align : center;'>" . $record['id'] . "</td>";

      echo '<select name="select" onchange="myJSFunction(this)">
                  <option></option>
                  <option>Approved</option>
                  <option>Pending</option>
                  <option>Disapproved</option>
            </select>';
      echo "</td>";
      echo "</tr>";
    }
  }

  echo "</ul>";
  echo '<a class="btn btn-lg btn-success btn-block tp" href="view.php" style="margin-left: 740px; bottom: -1px; position: relative;" onclick="history.back();">Back</a>';

?>  

And here is my jQuery code which I used for highlighting the row of the table cell:

<script type="text/javascript">

  function myJSFunction(element) {
    var color = ['none', 'green', 'yellow', 'red'];
    $('select').change(function() {
      $(this).parents('tr').css('background', color[$(':selected', this).index()]);
    })
  }

</script>

You also can create session when user change color , or you also can store color value in database

You can use cookies, you can get all related functions for cookies here

Set a blank cookie at the top of the page with

document.cookie="saveselect=";

Update the cookie in your javascript function each time the user changes any select like record['id']|'selected value',record['id']|'selected value', .....

While updating cookie you need to take care that cookies are overwritten and not updated means take the existing value, append the new to it and write the new data to the cookie.

Now while page load in the while loop you can take the value of the cookie explode it by '|' and convert it to array.

Now in each select search the created array if its value is saved in the cookie, If yes make the option selected by using the 'selected' attribute.This way your selected values will be in the select boxes.

You need to add the below script to the code. It will check all the select created and then will change each select color according to the selected value.

<script type="text/javascript">
$(document).ready(function(){
     var color = ['none', 'green', 'yellow', 'red'];
     $('select').each(function(){
        $(this).parents('tr').css('background', color[$(':selected', this).index()]);
     })
});
</script>

I have gave you the full logic and created the jquery to make the color for each select box.