I have a button that A) executes a PHP script and B) has a function to hide/show a loading indicator while the script is running.
While the script is running I want to disable the button. The problem I'm running into is that I can disable the button, but this prevents the PHP stuff from running.
Button
<form method="post">
<button id="CheckConnectionBtn" name="CheckConnectionBtn" class="CheckConnectionBtn" button onclick="ShowWaiting()">Test connection</button>
</form>
PHP
<?php
if(isset($_POST['CheckConnectionBtn'])){
$output = shell_exec("/script.sh");
$_SESSION["CONNECTION_CHECK"] = "$output";
}
?>
Function
<script>
function ShowWaiting() {
document.getElementById("loader_id").style.display = "block";
document.getElementById("loader_text_id").style.display = "block";
}
</script>
I tried adding $("#CheckConnectionBtn").attr("disabled", true);
to the function but this causes the loader to show up indefinitely, it appears the PHP is not triggered.
I also tried adding a onclick disabled to the button but this only causes a refresh of the page (loader shows up for a sec) and also does not appear to trigger the PHP.
Finally I tried adding
<script>
$("#CheckConnectionBtn").attr("disabled", true);
</script>
To the PHP but this causes a page that doesn't display anything even before clicking the button.
How can I disable the button on click but still trigger the php and my function?