Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
$(document).ready(function(){
$('#datatable tbody').on('click', 'td:nth-child(1), td:nth-child(5), td:nth-child(8), td:nth-child(11)', function (event) {
                if ($("#ValBool").val() == "false") {
                    Editable();
                }
                else {
                    event.stopImmediatePropagation();
                    alert("Not allowed");
                }
            });

function Editable(){

$('#datatable tbody').on('click', 'td:nth-child(1), td:nth-child(5), td:nth-child(8), td:nth-child(11)', function () {
                        
                        var x = $(".itemEdit").length;
                        var getData = $(this).html();
                        
                        //placing the data in the textbox again
                        if (x == 0) {
                            $(this).empty().html('<input type="text" value="' + getData + '" class="itemEdit" id="dataField"/>');
                            $('.itemEdit').focus();
                        }
});
}
</pre>




I want to trigger the second event on click on first event.


The problem is it is not getting triggered only the first time the page is loading but then it is working fine

The
JavaScript
$("#ValBool").val() == "false"
Is my condition for which i want to trigger the second event or not.
Posted
Updated 24-Sep-15 19:03pm
v2

1 solution

Your logic is bit wrong here.

Your first click event

JavaScript
$('#datatable tbody').on('click', 'td:nth-child(1), td:nth-child(5), td:nth-child(8), td:nth-child(11)', function (event) {


and the 2nd click event inside the Editable() function

JavaScript
$('#datatable tbody').on('click', 'td:nth-child(1), td:nth-child(5), td:nth-child(8), td:nth-child(11)', function () {


are both same. So, what you can do based on your logic is just remove the 2nd duplicate click event inside the Editable() function like:

JavaScript
$('#datatable tbody').on('click', 'td:nth-child(1), td:nth-child(5), td:nth-child(8), td:nth-child(11)', function (event) {
    if ($("#ValBool").val() == "false") {
        Editable(this);
    } else {
        event.stopImmediatePropagation();
        alert("Not allowed");
    }
});

function Editable(obj) {

    var x = $(".itemEdit").length;
    var getData = $(obj).html();

    //placing the data in the textbox again
    if (x == 0) {
        $(obj).empty().html('<input type="text" value="' + getData + '" class="itemEdit" id="dataField"/>');
        $('.itemEdit').focus();
    }
}


Let me know if you are still facing any issues.
 
Share this answer
 
Comments
lokopi.nagar 25-Sep-15 2:09am    
It worked!! thanks
Palash Mondal_ 25-Sep-15 2:25am    
Glad it helped!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900