My code looks like,
$("#OperationTypeId").change(function () {
var DropdownSelectionValue = $("#OperationTypeId :selected").val();
alert(DropdownSelectionValue );
if (DropdownSelectionValue == 3)
{
$("#Button1Id").attr('disabled');
$(" Button2Id").attr('enable');;
//$("#Button1Id").hide();
}
else {
$("#Button1Id").attr('enable');
$(" Button2Id").attr('disabled');;
}
});
My code shows alert value correctly but not make the buttons enable/disable with condition of DropdownSelectionValue. As iam the beginner i dont know how to do this. Kindly tell me.
From jQuery site
Properties generally affect the dynamic state of a DOM element without changing the serialized HTML attribute.
Examples include the value property of input elements, the disabled property of inputs and buttons, or the checked property of a checkbox.
The .prop() method should be used to set disabled and checked instead of the .attr() method.
To disable:
$('#Button1Id').prop('disabled', true);
To enable:
$('#Button2Id').prop('disabled', false);
http://api.jquery.com/prop/
Try This :-
$("#OperationTypeId").change(function () {
var DropdownSelectionValue = $("#OperationTypeId :selected").val();
if (DropdownSelectionValue == 3) {
$("#Button1Id").attr('disabled','disabled'); //or $("#Button1Id").prop('disabled',true);
$("#Button2Id").removeAttr('disabled'); //Use '#' id selector
}
else {
$("#Button1Id").removeAttr('disabled'); // or $("#Button1Id").prop('disabled',false);
$("#Button2Id").attr('disabled','disabled'); //Use '#' id selector
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With