Welcome Guest, Not a member yet? Register   Sign In
checkbox based input item
#8

(This post was last modified: 08-24-2018, 07:46 AM by Wouter60.)

To toggle the disabled property of the text inputs, first give all text and number inputs a class name and the disabled property: class="txtbox" disabled="disabled".
Then give the checkboxes the class name "cbx".

Load jQuery. Insert the following script:

Code:
<script>

$(document).ready(function(){
    $('.cbx').click(function(){
        v = $(this).is(':checked');
        row = $(this).parents('tr');
        if (v==true) {
            row.find('.txtbox').removeAttr('disabled');    
        }
        else {
            row.find('.txtbox').attr('disabled','disabled');
        }
        
    });

});

</script>

Now, if you click on one of the checkboxes, the text and number inputs on the same row are enabled or disabled.


Important:

Code:
$('.cbx')

is jQuery code for document.getElementsByClassName('cbx')
As you can see, jQuery makes your code far more simple!
Reply


Messages In This Thread
checkbox based input item - by kvanaraj - 08-20-2018, 11:35 PM
RE: checkbox based input item - by Pertti - 08-21-2018, 12:28 AM
RE: checkbox based input item - by kvanaraj - 08-21-2018, 01:40 AM
RE: checkbox based input item - by Pertti - 08-21-2018, 02:02 AM
RE: checkbox based input item - by kvanaraj - 08-21-2018, 02:34 AM
RE: checkbox based input item - by kvanaraj - 08-24-2018, 12:54 AM
RE: checkbox based input item - by InsiteFX - 08-24-2018, 03:13 AM
RE: checkbox based input item - by Wouter60 - 08-24-2018, 07:41 AM
RE: checkbox based input item - by kvanaraj - 08-24-2018, 11:00 PM
RE: checkbox based input item - by Wouter60 - 08-25-2018, 12:18 AM
RE: checkbox based input item - by kvanaraj - 08-25-2018, 12:44 AM
RE: checkbox based input item - by Wouter60 - 08-25-2018, 02:54 PM



Theme © iAndrew 2016 - Forum software by © MyBB