Is it possible to clear or empty a password field in a form after a download using JavaScript in PHP?

When a user downloads a file after submitting a form, the password field in the form may still contain the entered password. To clear or empty the password field after the download using JavaScript, you can add a script that resets the password field value once the download is initiated.

<?php
// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Process form data
    
    // After processing, initiate download
    // Add JavaScript to clear password field after download
    echo '<script>
            window.addEventListener("beforeunload", function() {
                document.getElementById("password_field").value = "";
            });
          </script>';
}
?>