Andy Green
asked on
Disable a radiobuttonlist item with JS or JQ
Hi
I have a radioButtonList, that is being populated server side.
There is a temp requirement to disable 1 of the options. There is no config for this so I'm looking to identify the element in the list and either hide it or disable it with JS or JQ
Can anyone offer any help?
Andy
I have a radioButtonList, that is being populated server side.
There is a temp requirement to disable 1 of the options. There is no config for this so I'm looking to identify the element in the list and either hide it or disable it with JS or JQ
Can anyone offer any help?
Andy
Can you share the HTML of the radiobutton list?
Can you paste your HTML code here?
ASKER
I have this function on the page load with seems to work except it leaves a gap in the list, OK I guess as its a temp requirement:
function hideOptions() {
var list = document.getElementById('r blAttendSt atus');
list.getElementsByTagName( 'input')[3 ].nextSibl ing.style. display = 'none';
list.getElementsByTagName( 'input')[3 ].style.di splay = 'none';
}
This is the HTML from the page source - Sorry its a dump.
<span id="rblAttendStatus"><span class="aspNetDisabled"><in put id="rblAttendStatus_0" type="radio" name="rblAttendStatus" value="1" checked="checked" disabled="disabled" /><label for="rblAttendStatus_0">li st Item 1</label></span><br /><span><input id="rblAttendStatus_1" type="radio" name="rblAttendStatus" value="2" /><label for="rblAttendStatus_1">li st Item 2</label></span><br /><span><input id="rblAttendStatus_2" type="radio" name="rblAttendStatus" value="4" /><label for="rblAttendStatus_2">li st Item 3</label></span><br /><span><input id="rblAttendStatus_3" type="radio" name="rblAttendStatus" value="5" /><label for="rblAttendStatus_3">li st Item 4</label></span><br /><span><input id="rblAttendStatus_4" type="radio" name="rblAttendStatus" value="6" /><label for="rblAttendStatus_4">li st Item 5</label></span><br /><span><input id="rblAttendStatus_5" type="radio" name="rblAttendStatus" value="7" /><label for="rblAttendStatus_5">li st Item 6</label></span><br /><span class="aspNetDisabled"><in put id="rblAttendStatus_6" type="radio" name="rblAttendStatus" value="8" disabled="disabled" /><label for="rblAttendStatus_6">li st Item 7</label></span></span>
Andy
function hideOptions() {
var list = document.getElementById('r
list.getElementsByTagName(
list.getElementsByTagName(
}
This is the HTML from the page source - Sorry its a dump.
<span id="rblAttendStatus"><span
Andy
Since you're using jQuery:
$('input[type=radio]:eq(3)').attr('disabled', true);
ASKER
How does that target the rbl control?
A
A
It targets the 4th radiobutton on the page.
If you don't have any others, it should work just fine.
If you don't have any others, it should work just fine.
Since they each have their own ID, you can use this instead, which will work even with other radiobuttons on the page:
$('#rblAttendStatus_3').attr('disabled', true);
ASKER
OK thanks, needs to be more specific, there are radios on other tabs. Its quite a large page.
A
A
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Julian. Learned a lot form your response. Thanks also to the other for your time.
Andy
Andy
You are welcome.