0

Good Day,

So I have three pages with the following scripts I would like to disable this button(sign button) along with 4 other buttons eg (add, update, change-status, delete) once the sign button is clicked

Please note the buttons I mentioned before have similar scripts as the sign script below just the actual function that the buttons perform are different for eg the add button would insert a new record, update would update a record etc)

enter image description here

Any assistance would be greatly appreciated.

Script 1 index.php

$(document).on('click','.sign', function(){
    var expenditureid = $(this).attr("id");

    var btn_action = 'sign';
    if(confirm("Are you sure you want to sign this expenditure?"))
    {
        $.ajax({
            url:"expenditure_action.php",
            method:"POST",
            data:{expenditureid:expenditureid, btn_action:btn_action},
            success:function(data)
            {
                $('#alert_action').fadeIn().html('<div class="alert alert-info">'+data+'</div>');
                expendituredataTable.ajax.reload();
            }
        })
    }
    else
    {
        return false;
    }
});

Script 2 action.php

            if($_POST['btn_action'] == 'sign') {
            $signed = "yes";
                $query = "
                UPDATE expenditure
                set checking_officer = :checking_officer,
                modified_by = :modified_by,
                signed = :signed

            WHERE expenditureid = :expenditureid
                ";
                $statement = $connect->prepare($query);
                $statement->execute(
                    array(
                            ':checking_officer'                     =>  $_SESSION["user_id"],
                                    ':modified_by'                      =>  $_SESSION["user_id"],
                            ':signed'                       =>  $signed,
                        ':expenditureid'                        =>  $_POST["expenditureid"]
                    )
                );

Script 3 fetch.php

$sub_array[] = "<button type='button' name='sign' id='".$row['expenditureid']."' class='btn btn-secondary btn-xs sign'>Sign";

$sub_array[] = "<button type='button' name='delete' id='".$row['expenditureid']."' class='btn btn-danger btn-xs delete'>Delete";

2 Answers 2

1

you can use this function


function disable_buttons (buttons) {
 buttons.each(function(){
   $(this).attr("disabled", "disabled")
 })
}

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you will try it!
1

$(".sign").on("click", function() {
  const $otherButtons = $(this).closest("tr").find("button");
  $otherButtons.prop({disabled: true});
});
<table>
  <tr>
    <td><button type="button">Update</button></td>
    <td><button type="button" class="sign">Sign</button></td>
    <td><button type="button">Delete</button></td>
    <td><button type="button">Change Status</button></td>
  </tr>
</table>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

2 Comments

Thank you..I tried this script However the buttons are re-enabling after the page reloads
@Ria JS has no state unless you store it in Database or locally on the user machine (i.e: using a Storage API like localStorage). You should - on a subsequent page request know how to handle those disabled states - such should be served by your backend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.