locked
if checkbox checked put true or false into the input inside td RRS feed

  • Question

  • User-1634604574 posted

    i have this table i want when checkbox checked in each td put true into the input with name check if not checked

    put false into that checkbox and then by button click show value in input with name index by alert

    <table>
    <tr>
    <td>
    <input type="checkbox" value="check1">
    <input type="text" name="check">
    <input type="text" name="index">
    </td>
    
    <td>
    <input type="checkbox" value="check2">
    <input type="text" name="check">
    <input type="text" name="index">
    </td>
    
    <td>
    <input type="checkbox" value="check3">
    <input type="text" name="check">
    <input type="text" name="index">
    </td>
    </tr>
    
    <tr>
    <td>
    <input type="checkbox" value="check4">
    <input type="text" name="check">
    <input type="text" name="index">
    </td>
    
    <td>
    <input type="checkbox" value="check5">
    <input type="text" name="check">
    <input type="text" name="index">
    </td>
    
    <td>
    <input type="checkbox" value="check6">
    <input type="text" name="check">
    <input type="text" name="index">
    </td>
    </tr>
    
    <tr>
    <td>
    <input type="checkbox" value="check7">
    <input type="text" name="check">
    <input type="text" name="index">
    </td>
    
    <td>
    <input type="checkbox" value="check8">
    <input type="text" name="check">
    <input type="text" name="index">
    </td>
    
    <td>
    <input type="checkbox" value="check9">
    <input type="text" name="check">
    <input type="text" name="index">
    </td>
    </tr>
    </table>
    
    

    Wednesday, May 1, 2019 9:55 PM

All replies

  • User839733648 posted

    Hi 

    According to your description and code, I'm sorry I could not understand your requirement clearly.

    i have this table i want when checkbox checked in each td put true into the input with name check if not checked

    There are two inputs in each td, could you explain that which input you want to put true or false?

    What is the name check? Do you mean the name attribute of input?

    put false into that checkbox and then by button click show value in input with name index by alert

    I'm confused about this sentence, could you describe clearly?

    If you provide your requirement clearly, this will help you to solve your issue easily.

    Best Regards,

    Jenifer

    Thursday, May 2, 2019 2:46 AM
  • User-1634604574 posted

    i want to put true into the first input text which is name is check

    Thursday, May 2, 2019 4:48 AM
  • User839733648 posted

    Hi zhyanadil.it@gmail.com,

    Do you want something like this?

    I've made a demo and maybe you could refer to.

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
        <script>
            $(function () {
                checkTest();
                $("#check1").click(function () {
                    if ($(this).is(":checked")) {
                        $("input[name*='check']").val("true");
                        $("input[name*='index']").val(" ");
                    }
                    else {
                        $("input[name *= 'index']").val("false");
                        $("input[name*='check']").val(" ");
                        alert("No Checked");
                    }
                })
                function checkTest() {
                    if ($(this).is(":checked")) {
                        $("input[name*='check']").val("true");
                        $("input[name*='index']").val(" ");
                    }
                    else {
                        $("input[name *= 'index']").val("false");
                        $("input[name*='check']").val(" ");
                        alert("No Checked");
                    }
                }
            })
    
        </script>
    </head>
    <body>
        <table>
            <tr>
                <td>
                    <input type="checkbox" value="check1" id="check1">
                    <input type="text" name="check">
                    <input type="text" name="index">
                </td>
            </tr>
        </table>
    </body>
    </html>

    Best Regards,

    Jenifer

    Thursday, May 2, 2019 7:49 AM