0

I want to disable onclick event after successful ajax request

<div class="report_button" id="report_button" title="Reportthis" style="width:65px;height:15px;" onclick="reported_text(user_id,lead_id);">Report</div>

this is my div which i want to disable div after clicked

function reported_text(user_id,lead_id){
    new Ajax.Request("/agent/report/lead-refund",
    {
        method:"POST",
        parameters:"user_id=" + user_id + "&lead_id=" + lead_id ,
        onSuccess: function(transport){
            alert("Thank you for Response");
            jQuery('#report_button').attr("disabled", "disabled");
        },
        onFailure: function(transport){

            $('tag_error_status').innerHTML = '';
            alert("Unsuccessful request processing. This will be rectified soon.");
        }
    });
}

is there any way to do this. and this div is used for many users, i have to do it in such a way so that it only disable for particular user.

SAC
  • 243
  • 3
  • 13

3 Answers3

3
 new Ajax.Request("/agent/report/lead-refund",
    {
        method:"POST",
        parameters:"user_id=" + user_id + "&lead_id=" + lead_id ,
        onSuccess: function(transport){
            alert("Thank you for Response");
            jQuery('#report_button').hide();
        },
        onFailure: function(transport){

            $('tag_error_status').innerHTML = '';
            alert("Unsuccessful request processing. This will be rectified soon.");
        }
    });

You can use hide function to do so... or you can use $("#report_button").attr("onclick","")

Vivek Aasaithambi
  • 919
  • 11
  • 23
1

Depends on how you added the listener try the one that suits: if you used $(document).on then use:

$(document).off("click", "#report_button");

if you used $("#report_button").on then use:

$("#report_button").off

or just use:

$("#report_button").click(function(){ return false; });
hatzaviv
  • 159
  • 2
  • 14
0

You can disable click like this:

document.getElementById("report_button").onmousedown = new function ("return false");

Here is where I found this code link

Community
  • 1
  • 1
brso05
  • 13,142
  • 2
  • 21
  • 40