简体   繁体   中英

javascript getting input checkbox on table using col and row

I want to make proses where my data is exist the checkbox will become false , so here is the image that i tried, and using with console. 在此处输入图像描述

I tried to get the column and row to make checkbox become false like here.

    let tblModul = document.getElementById('myTable');
    console.log('col :' + col);
    console.log('row :' + row);
    const [intersections, difference, falsecheked] = datarelationships(theemployee, theEmpDatInTable, 'nik', 'NIK');
    appendTheTableEmployee(difference.length, tbody, difference)
    console.log(falsecheked);
    if(falsecheked == false){
        tblModul.rows[row].cells[col].checked = false;
    }

Is there a problem with my code? because eventough i got the value false, the checkbox didn't unchecked

You are using tblModul.rows[row].cells[col].checked = false; which will try to set checked = false on cell but you need to perform it on input inside that cell . So you can use like tblModul.rows[row].cells[col].querySelector('input').checked = false; .

Try it below.

 let tblModul = document.getElementById('myTable'); // in your code use row & col variables I have statically used for testing. tblModul.rows[0].cells[0].querySelector('input').checked = false; tblModul.rows[1].cells[0].querySelector('input').checked = true;
 <table id='myTable'> <tr> <td><input type='checkbox' checked></td> </tr> <tr> <td><input type='checkbox' checked></td> </tr> </table>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM