Reputation: 10575
Here is my problem .On change of the Data in the textfield txt1 we send a request to json file which outputs the status of that value entered in thetextfield with that status (Y means ) "Yes " is checked and (N means) "No" is checked and if no value is present than "NO" is only checked. Here is the code below but for ex if we enter "213 " value means "A" so status is "YES" so "YES" is checked and "NO" is "DISABLED" ."214 " means "B" so status means "NO" so "NO " is checked and "disabled" and " yes" is also "disabled ". The "NO " should only be checked and not"DISABLED" this might be we have "DISABLED" in the previous "YES".
$.getJSON("test.php",{'val' : $("#txt1").attr('value'),'cde' :$("#txt2").attr('value')},
function(data){
if(data[0].status){
switch(data[0].status){
case 'A':
$('#rb_Statusyes').attr('checked',true);
$('#rb_Statusno').attr('disabled','disabled');
break;
case 'B':
$('#rb_Statusno').attr('checked',true);
$('#rb_Statusyes').attr('disabled','disabled');
break;
case '':
$('#rb_Statusno').attr('checked',true);
$('#rb_Statusyes').attr('disabled','disabled');
break;
}
}
Upvotes: 0
Views: 539
Reputation: 9841
It looks ok the code but try this
//disable options
$('#rb_Statusyes').attr('checked', true);
$('#rb_Statusno').attr('disabled', true);
//enable options
$('#rb_Statusno').removeAttr('disabled');
Upvotes: 0
Reputation: 14409
If I understand you correctly, your problem is that you've previously set the attribute and you now need to remove it.
$('#rb_Statusno').attr('checked',true);
$('#rb_Statusno').removeAttr('disabled'); // Also remove the previously added disabled
$('#rb_Statusyes').attr('disabled','disabled');
$('#rb_Statusyes').removeAttr('checked'); // Also remove the previously added checked
Upvotes: 1