locked
check checkbox checked inside table RRS feed

  • Question

  • User-1634604574 posted
    i want to check if second column value is True checkbox of first column checked if false not checked

    <table> <tr> <td><input type="checkbox"></td> <td><input type="text" value="True"></td> <tr> <tr> <td><input type="checkbox"></td> <td><input type="text" value="Flase"></td> <tr> <tr> <td><input type="checkbox"></td> <td><input type="text" value="True"></td> <tr> </table>

    Monday, July 1, 2019 12:39 PM

Answers

  • User-1174608757 posted

    Hi zhyanadil.it@gmail.com,

    According to your description,I suggest that you could use jquery to accomplish your requirement.Here is the demo, I hope it could help you.

    <head runat="server">
        <title></title>
        <script src="Scripts/jquery-3.3.1.js"></script>
        <script>
            $(function () {
    //find all text control in table            
                var texts = $("#table1").find('input[type=text]');
    //if text of text control is true ,find the checkbox and set as checked
                texts.each(function () {
    
                    if ($(this).val().trim() == "True") {
                        $(this).parent().siblings().children().prop('checked',true);
                       
                    }
    
    
    
                })
               
              
    
            })
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <table id="table1" style="width: 100%;">
                    <tr>
                        <td><input type="checkbox"/></td>
                        <td><input type="text" value="True" /></td>
                    </tr>
                    <tr>
                        <td><input type="checkbox" /></td>
                        <td><input type="text" value="False" /></td>
                        
                    </tr>
                    <tr>
                        <td><input type="checkbox" /></td>
                        <td><input type="text" value="True" /></td>
                    </tr>
                </table>
            </div>
        </form>
    </body>
    </html>
    

    It shows as below:

    Best Regards

    Wei

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 2, 2019 2:33 AM

All replies

  • User475983607 posted

    There are too many issues with the code shown to guess what you are doing.  The code is missing Ids and names and has a typo.  Secondly do you really want values of True and False?  As written, it is difficult to map the check mark to a column or property name.  Can you provide a high level overview of what you are trying to do?

    Is there anyway, you can post a better example of what you are trying to do?

    Monday, July 1, 2019 1:18 PM
  • User-1174608757 posted

    Hi zhyanadil.it@gmail.com,

    According to your description,I suggest that you could use jquery to accomplish your requirement.Here is the demo, I hope it could help you.

    <head runat="server">
        <title></title>
        <script src="Scripts/jquery-3.3.1.js"></script>
        <script>
            $(function () {
    //find all text control in table            
                var texts = $("#table1").find('input[type=text]');
    //if text of text control is true ,find the checkbox and set as checked
                texts.each(function () {
    
                    if ($(this).val().trim() == "True") {
                        $(this).parent().siblings().children().prop('checked',true);
                       
                    }
    
    
    
                })
               
              
    
            })
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <table id="table1" style="width: 100%;">
                    <tr>
                        <td><input type="checkbox"/></td>
                        <td><input type="text" value="True" /></td>
                    </tr>
                    <tr>
                        <td><input type="checkbox" /></td>
                        <td><input type="text" value="False" /></td>
                        
                    </tr>
                    <tr>
                        <td><input type="checkbox" /></td>
                        <td><input type="text" value="True" /></td>
                    </tr>
                </table>
            </div>
        </form>
    </body>
    </html>
    

    It shows as below:

    Best Regards

    Wei

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 2, 2019 2:33 AM