0

Ive been figuring out how to enable an array of textbox when their corresponding checkbox is being checked using javascript...

Here is my code:

    $line_util3 = "Select id_code,description from WEBLOAN_SERVER.webloan.dbo.mis_group where pid_code='$list_count' and group_no = '0' and child_node = '1' ";
    $stmt_line_util3=sqlsrv_query($conn, $line_util3);

    if(!$stmt_line_util3) {
        die( print_r( sqlsrv_errors(), true));
        }

    sqlsrv_execute($stmt_line_util3);

    while ($imps_row1 = sqlsrv_fetch_array($stmt_line_util3,SQLSRV_FETCH_ASSOC))

    {

    echo "<tr>";
    echo "<td><input type='checkbox' name='op[]'></td>";
    echo "<td>" . $imps_row1['id_code'] . " - " . $imps_row1['description'] . "</td>";
    echo "<td><input type='text' disabled='disabled' name='txt[]'></td>";
    echo "</tr>";

    }

Thank You very much for the Help

1
  • i added a code .if u have any doubt please let me know. Commented Oct 29, 2013 at 5:38

2 Answers 2

1

Try this i hope this will help you. Which uses jQuery.

$(document).on('click', 'input[name="op[]"]', function () {
    var checked = $(this).prop('checked');// true or false
    if (checked) {
        $(this).parents('tr').find('td input[type="text"]').removeAttr('disabled');
    }
    else {
        $(this).parents('tr').find('td input[type="text"]').attr('disabled', 'disabled');
    }
});

here is updated the Demo

Sign up to request clarification or add additional context in comments.

2 Comments

do i still need to download the jquery plugin for this? if yes, where could i download it... thank you @bios
Here jQuery Downloads I've updated the answer do check.
1

add an onclick event to call a javascript function to ur checkbox then assign id to the different text box whom u want to disable or enable/disaapear or appear.in the following code i am enabling text box with id 'tpnr' and disabling the other text boxes(id:bs,as)

<script type="text/javacript">
function(a){
    document.getElementById("tpnr").style.position = "static";
    document.getElementById("tpnr").style.top = "0px";
    document.getElementById("bs").style.position = "absolute";
    document.getElementById("bs").style.top = "-10000px";
    document.getElementById("as").style.position = "absolute";
    document.getElementById("as").style.top = "-10000px";
}
</script>

2 Comments

textbox are dynamically added... i cant assign a id on each textbox i can only use one id for all texboxes but using array
u can dynamically assign id also like t1,t2,t3 etc inside the while loop.take one more variable and increment it with while loop and correspondingly assign it as id of the particular checkbox.

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.