You are viewing limited content. For full access, please sign in.

Question

Question

Update Checkbox in table using JavaScript

asked on August 10, 2019 Show version history

I was looking for a way to have a checkbox updated using lookups from the database but I wasn't able to find anything.

 

My next plan is to try and use JavaScript to update the checkbox in the rows within the table.  See picture below for example:

The idea for each row would be if Box1 Bit = 1, set checkbox Box1.

If Box2 Bit = 1, set checkbox Box 2.  Otherwise uncheck box.

Any idea if this is something that can be pulled off using JavaScript?

0 0

Replies

replied on August 12, 2019 Show version history

Yes, you can do this with JavaScript. The lookups should trigger a change event, and you can use delegated event handlers to monitor the table and respond to specific changes.

Assign a custom class to your  table, checkbox field, and the two lookup fields. Something like myTable, myCheckbox, myLookup1, and myLookup2.

Then you could do something like this,

$(document).ready(function(){
    // first lookup column
    $('.myTable').on('change','.myLookup1 input',function(index,value){
        // get first check box in field and set checked attribute
        $(this).parents('tr').find('.myCheckbox input').eq(0).prop('checked',(value == 1));
    });

    // second lookup column
    $('.myTable').on('change','.myLookup2 input',function(index,value){
        // get first check box in field and set checked attribute
        $(this).parents('tr').find('.myCheckbox input').eq(1).prop('checked',(value == 1));
    });
});

 

0 0
replied on August 12, 2019

I am not getting any updates to the checkbox when I update the 'myLookup1' or 'myLookup2' fields manually.

Am I missing another trigger to call these functions properly?

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.