dhamo dharan
dhamo dharan

Reputation: 762

How to enable text box on check box check

I am trying to enable and disable of text box when check box checked. But here only one text box enabled when the check box checked. How to enable and disable two text box when check box checked ? Here is my code:

<script src="plugins/jQuery/jquery-2.2.3.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
    $('.input_control').change(function () {
        $('input[name=' + this.value + ']')[0].disabled = !this.checked;
    }).change();
});
</script>

thanks in advance..!!

Upvotes: 0

Views: 76

Answers (2)

Narek Arzumanyan
Narek Arzumanyan

Reputation: 616

 $('input[name=' + this.value + ']')[0].prop( "disabled", !this.checked);


EDIT:

 $('input[name=' + this.value + ']').first().prop( "disabled", !this.checked);
 $('input[name=' + this.value + ']').prop( "disabled", !this.checked);

Upvotes: 0

Satpal
Satpal

Reputation: 133403

[0] will only return you single DOM element, thus it working for single element.

Since you need to modify value of multiple element, You should use .prop( propertyName, value ) method

Set one or more properties for the set of matched elements.

$('input[name=' + this.value + ']').prop("disabled", !this.checked);

Upvotes: 1

Related Questions