Hi I have the javascript fuction and where i am trying to disable the input box based on check box checked in jquery mobile.But its not working means the value itself it is not taking.Then how to achieve that?
why the input box is not disable while checking the check box?
94 Views Asked by S Das At
5
There are 5 best solutions below
1

You can use prop()
method to disable the input field, also it's better to use change()
event instead of click()
$('[name="PD6"]').change(function() {
if (this.checked) {
$(this).val("Y");
$('[name="PD7"]').prop("disabled", false);
} else {
$(this).val("N");
$('[name="PD7"]').prop("disabled", true);
}
}).change();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div role="main" class="ui-content">
<div class="ui-grid-a">
<div class="ui-block-a">
<input name="PD6" id="PD6" type="checkbox" />
<label for="PD6">Other Disability</label>
</div>
<div class="ui-block-b theText">
<input type="text" name="PD7" value="" />
</div>
</div>
</div>
0

$('[name="PD7"]').css("disabled", "false");
This is not the right way to disable/enable input.
You need to use prop()
$('[name="PD7"]').prop("disabled", false);
0

document.getElementById()
wont work onname
attributeUse
.prop()
instead ofcss()
ascss()
is used for styling.
$('[name="PD6"]').click(function () {
$('[name="PD7"]').prop("disabled", !this.checked);
this.value = this.checked? "Y": "N";
});
$('[name="PD6"]').click(function () {
$('[name="PD7"]').prop("disabled", !this.checked);
$('[name="PD6"]').val(this.checked? "Y": "N");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div role="main" class="ui-content">
<div class="ui-grid-a">
<div class="ui-block-a">
<input name="PD6" id="PD6" type="checkbox" />
<label for="PD6">Other Disability</label>
</div>
<div class="ui-block-b theText">
<input type="text" name="PD7" value="" />
</div>
</div>
</div>
Use
prop
todisable
the checkbox:css
is used to set the style of the matching selector.Docs: https://api.jquery.com/prop
EDIT
Some Optimizations: