When I have a form with a submit button that triggers a form submission on a PHP page, I want to have an onclick event on the submit button that changes its opacity using JavaScript. The issue I am facing is that after clicking the submit button, the opacity changes, the form submits, and then the button's opacity resets back to 100%. I want the opacity attribute to remain on the button even after the form submission. See my codes below:
<script type="text/javascript">
function fadebtn(){
document.getElementById('submitbtn').style.opacity="0.4";
}
</script>
<form method="post">
<input type="submit" value="Submit" id="submitbtn" name="submitbtn">
</form>
UPDATE: I have now resolved this issue. Please refer to the updated codes above and the additional codes below.
<?php
if(isset($_POST['submitbtn']))
{
echo '<script type="text/javascript">'
, 'fadebtn()'
, '</script>';
}