Link to home
Start Free TrialLog in
Avatar of Andy Green
Andy GreenFlag for United Kingdom of Great Britain and Northern Ireland

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
Avatar of Sam Jacobs
Sam Jacobs
Flag of United States of America image

Can you share the HTML of the radiobutton list?
Can you paste your HTML code here?
Avatar of Andy Green

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('rblAttendStatus');
            list.getElementsByTagName('input')[3].nextSibling.style.display = 'none';
            list.getElementsByTagName('input')[3].style.display = 'none';

        }


This is the HTML from the page source - Sorry its a dump.

<span id="rblAttendStatus"><span class="aspNetDisabled"><input id="rblAttendStatus_0" type="radio" name="rblAttendStatus" value="1" checked="checked" disabled="disabled" /><label for="rblAttendStatus_0">list Item 1</label></span><br /><span><input id="rblAttendStatus_1" type="radio" name="rblAttendStatus" value="2" /><label for="rblAttendStatus_1">list Item 2</label></span><br /><span><input id="rblAttendStatus_2" type="radio" name="rblAttendStatus" value="4" /><label for="rblAttendStatus_2">list Item 3</label></span><br /><span><input id="rblAttendStatus_3" type="radio" name="rblAttendStatus" value="5" /><label for="rblAttendStatus_3">list Item 4</label></span><br /><span><input id="rblAttendStatus_4" type="radio" name="rblAttendStatus" value="6" /><label for="rblAttendStatus_4">list Item 5</label></span><br /><span><input id="rblAttendStatus_5" type="radio" name="rblAttendStatus" value="7" /><label for="rblAttendStatus_5">list Item 6</label></span><br /><span class="aspNetDisabled"><input id="rblAttendStatus_6" type="radio" name="rblAttendStatus" value="8" disabled="disabled" /><label for="rblAttendStatus_6">list Item 7</label></span></span>


Andy
Since you're using jQuery:
$('input[type=radio]:eq(3)').attr('disabled', true); 

Open in new window

How does that target the rbl control?

A
It targets the 4th radiobutton on the page.
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); 

Open in new window

OK thanks, needs to be more specific, there are radios on other tabs. Its quite a large page.

A
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you Julian. Learned a lot form your response. Thanks also to the other for your time.

Andy
You are welcome.