-2

I have a radiobutton list that is rendered as

<input id="rblOD_1" type="radio" name="ctl00$ContentPlaceHolder1$rblOD" value="1">
<input id="rblOD_2" type="radio" name="ctl00$ContentPlaceHolder1$rblOD" value="2">
<input id="rblOD_3" type="radio" name="ctl00$ContentPlaceHolder1$rblOD" value="3">

I want to disable the last item only on page load and enable it after doing checks from the db. I am doing this to do it

$("input:radio[name='ctl00$ContentPlaceHolder1$rblOD'][value='3']")
    .attr('disabled', 'disabled');

It doesn't work on load but it works in the radiobuttonlist change event. How can I get it to work on load or without any click or change events?

freedomn-m
  • 27,664
  • 8
  • 35
  • 57
JohnnyCage
  • 175
  • 1
  • 1
  • 11
  • Does the page actually render like that and are you doing `$(function() { $("input:radio[name='ctl00$ContentPlaceHolder1$rblOD'][value='3']").attr('disabled', 'disabled'); });` – mplungjan Jun 14 '23 at 12:58
  • 1
    1) is your code within document.ready (see [learn.jquery.com](https://learn.jquery.com/using-jquery-core/document-ready/)) *or* appearing after your `inputs`? – freedomn-m Jun 14 '23 at 13:07
  • It is rendered as an HTML table with TR and TD tags. Each option is in a separate TR tag. And I am calling a function in the $(document).ready(function () { DisableRadio(); } – JohnnyCage Jun 14 '23 at 13:08
  • 2) are your inputs generated *dynamically* - ie after the page has finished loading (without the inputs) then load the inputs via ajax or similar – freedomn-m Jun 14 '23 at 13:08
  • 1
    they are not dynamic. It's defined as a static asp:radiobuttonlist control – JohnnyCage Jun 14 '23 at 13:09
  • Then you'll need to provide a complete snippet that demonstrates the issue (see [mcve]) as it's trivial to show that the code you've provided, *as provided*, works fine: https://jsfiddle.net/shy9nbum/ – freedomn-m Jun 14 '23 at 13:09
  • PS https://en.wikipedia.org/wiki/Placeholder has a lowercase `h` – Roko C. Buljan Jun 14 '23 at 13:16
  • This is a duplicate of https://stackoverflow.com/questions/14028959/why-does-jquery-or-a-dom-method-such-as-getelementbyid-not-find-the-element – Roko C. Buljan Jun 14 '23 at 13:21
  • @RokoC.Buljan better tell Microsoft, not much we can do about it inside an MS wrapper: https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.placeholder?view=netframework-4.8.1&viewFallbackFrom=net-8.0 – freedomn-m Jun 14 '23 at 13:31

1 Answers1

0

The code is actually working now. The reason it wasn't working was because in the code-behind there was a script that was being called in the pageload that was re-enabling the radiobutton item.

$("input:radio[name='ctl00$ContentPlaceHolder1$rblOD'][value='3']") .attr('disabled', 'disabled');

This is the working code

Thanks

JohnnyCage
  • 175
  • 1
  • 1
  • 11