      <div class="modal fade" id="edit-admin<?= htmlentities($user_session); ?>">
          <div class="modal-dialog modal-sm">
              <div class="modal-content">
                  <div class="modal-header">
                      <h4 class="modal-title">Manage Admin</h4>
                      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                          <span aria-hidden="true">&times;</span>
                      </button>
                  </div>
                  <div class="modal-body">
                    <div id="msg-adminedit"></div>
                    <form method="POST">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label>Username:</label>
                                    <input class="form-control input-sm" type="text" id="edit_username" alt="username2" autocomplete="off" />
                                    <label id="msg-username2" style="color:#CC0000;" ></label>
                                </div>
                                <div class="form-group">
                                    <label>Password:</label>
                                    <input class="form-control input-sm" type="password" id="edit_password" alt="password2"  autocomplete="off" />
                                </div>

                            </div>
                        </div>
                  </div>
                  <div class="modal-footer justify-content-between">
                      <input type="hidden" id="edit_userid">
                      <input type="hidden" alt="user" id="user" value="<?= htmlentities($user_session); ?>">
                      <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                      <button type="button" class="btn btn-primary" id="edit-admn">Update</button>
                  </div>
                  </form>
              </div>
          </div>
      </div>
      <script>
          document.addEventListener('DOMContentLoaded', () => {
              let btn = document.querySelector('#edit-admn');
              btn.addEventListener('click', () => {

                  const username = document.querySelector('input[alt=username2]').value;
                  const password = document.querySelector('input[alt=password2]').value;
                  const user_id = document.querySelector('input[id=edit_userid]').value;
                  const user = document.querySelector('input[alt=user]').value;

                  var data = new FormData(this.form);

                  data.append('username', username);
                  data.append('password', password);
                  data.append('user_id', user_id);
                  data.append('user', user);


                      $.ajax({
                          url: '../../controllers/edit_admin.php',
                          type: "POST",
                          data: data,
                          processData: false,
                          contentType: false,

                          async: false,
                          cache: false,

                          success: function(data) {
                              $('#msg-adminedit').html(data);

                          },
                          error: function(data) {
                              console.log("Failed");
                          }
                      });
               //   }

              });
          });
      </script>

      <script type="text/javascript">
    $(document).ready(function() {
 
        var timeOut = null; // this used for hold few seconds to made ajax request
 
        var loading_html = '<img src="../../images/ajax-loader.gif" style="height: 20px; width: 20px;"/>'; // just an loading image or we can put any texts here
 
        //when button is clicked
        $('#edit_username').keyup(function(e){
 
            // when press the following key we need not to make any ajax request, you can customize it with your own way
            switch(e.keyCode)
            {
                //case 8:   //backspace
                case 9:     //tab
                case 13:    //enter
                case 16:    //shift
                case 17:    //ctrl
                case 18:    //alt
                case 19:    //pause/break
                case 20:    //caps lock
                case 27:    //escape
                case 33:    //page up
                case 34:    //page down
                case 35:    //end
                case 36:    //home
                case 37:    //left arrow
                case 38:    //up arrow
                case 39:    //right arrow
                case 40:    //down arrow
                case 45:    //insert
                //case 46:  //delete
                    return;
            }
            if (timeOut != null)
                clearTimeout(timeOut);
            timeOut = setTimeout(is_available, 500);  // delay delay ajax request for 1000 milliseconds
            $('#msg-username').html(loading_html); // adding the loading text or image
        });
  });
function is_available(){
    //get the username
    var username = $('#edit_username').val();
 
    //make the ajax request to check is username available or not
    $.post("check_usernameadmin.php", { username: username },
    function(result)
    {
        console.log(result);
        if(result != 0)
        {
            $('#msg-username2').html('Not Available');
            document.getElementById("edit-admn").disabled = true;
        }
        else
        {
            $('#msg-username2').html('<span style="color:#006600;">Available</span>');
            document.getElementById("edit-admn").disabled = false;
        }
    });
 
}
</script>
