0

I am currently creating tables and checkboxes using ajax communication.

After it was created, it was confirmed that the checkbox function was working normally, Even if I include checked while creating it, the onclick function doesn't fire.

success:function(data){
    for (var key in data) {
        feature = data[key]
        head = feature[0].split(" ")
        tail = feature[1].split(" ")
        type = feature[2]
        name = feature[3]
        $('#pharmacophore_table').append("<tr>" + 
            "<td>" + name + "</td>" +
            "<td> <label><input type='checkbox' name='ligand_feature' onclick='show_ligand_feature(this, " + '"' + feature + '"' + ");' ></label>" + 
            "</tr>");

        $("input[name='ligand_feature']").attr( "checked", true);
    }      
},
error:function(data){
    alert(data.status)
}

How can I solve this?

5
  • Those quotes don't look right to me. Does the input render properly in the DOM so the onclick looks right there? Commented Dec 23, 2021 at 2:40
  • After creation the onclick function works fine. The problem is that the onclick function does not work when created and checked with the ajax function. Commented Dec 23, 2021 at 2:44
  • Are you expecting the onclick function to be called when you set checked? Commented Dec 23, 2021 at 2:45
  • Yes I want to enable all checkboxes at the same time as they are created. Commented Dec 23, 2021 at 2:48
  • Ok but it's still not clear what isn't working and why. Can you create a demo that reproduces the problem? See minimal reproducible example Commented Dec 23, 2021 at 2:53

1 Answer 1

1

I solved it.

Just add click event

complete: function(){
    var chck = document.getElementsByName('ligand_feature')
    for (var l=0; l<chck.length; l++){
        chck[l].click();
    }
Sign up to request clarification or add additional context in comments.

Comments

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.