I have two radio buttons to select priority as high or regular.
I wrote this function to disable the radiobox which was not selected. For some reason it won't disable the box though. I get no error in the consol.
function disablePriority(){
var reg = $('input[value="ct100"]');
var high = $('input[value="ct101"]');
alert('cp');
if(reg.attr("checked")){
alert('cp1');
high.attr("disabled","disabled");
}else{
alert('cp2');
reg.attr("disabled","disabled");
}
}
This is the html for the two radio boxes
<input id="ctl00_m_g_72c1058f_372a_4780_b0c6_58f4c7012b35_ff61_ctl00_ctl00" type="radio" name="ctl00$m$g_72c1058f_372a_4780_b0c6_58f4c7012b35$ff61$ctl00$RadioButtons" value="ctl00">
<input id="ctl00_m_g_72c1058f_372a_4780_b0c6_58f4c7012b35_ff61_ctl00_ctl01" type="radio" name="ctl00$m$g_72c1058f_372a_4780_b0c6_58f4c7012b35$ff61$ctl00$RadioButtons" value="ctl01" checked="checked">
Try with disabled
as true
like
if(reg.attr("checked")){
high.attr("disabled",true);
}else{
reg.attr("disabled",true);
}
CHeck this FIDDLE
high.attr("disabled",'disabled'); or high.prop("disabled",'true');
high[0].disabled=true;high[1].disabled=true
high.removeAttr("disabled"); //to remove it
Ok, first there is a typo in your input value
. In the HTML it is ctl01 and ctl00 (note the small-case 'L'). In your jQuery it is ct100 and ct101.
Change the value as below, it works.
var reg = $('input[value="ctl00"]');
var high = $('input[value="ctl01"]');
if(reg.prop("checked")){
alert('cp1');
high.prop("disabled",true);
}else{
alert('cp2');
reg.prop("disabled", true);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.