user1457613
user1457613

Reputation: 115

jquery - enable specific items in asp.net radiobuttonlist

I know this has been asked before, but it is not working for my scenario. I have a jquery ui modal form which contains a radiobuttonlist with static values:

    <asp:RadioButtonList ID="rblSlots" runat="server" ViewStateMode="Disabled">
    <asp:ListItem Value="30" enabled="false">30 Minutes</asp:ListItem>
    <asp:ListItem Value="60" enabled="false">1 Hour</asp:ListItem>
    <asp:ListItem Value="90" enabled="false">1 1/2 Hours</asp:ListItem>
    <asp:ListItem Value="120" enabled="false">2 Hours</asp:ListItem>
    <asp:ListItem Value="150" enabled="false">2 1/2 Hours</asp:ListItem>
    <asp:ListItem Value="180" enabled="false">3 Hours</asp:ListItem>
    </asp:RadioButtonList>

Which of course renders as:

    <table id="rblSlots">
    <tr>
    <td><span disabled="disabled"><input id="rblSlots_0" type="radio" name="rblSlots" value="30" disabled="disabled" /><label for="rblSlots_0">30 Minutes</label></span></td>
    </tr><tr>
    <td><span disabled="disabled"><input id="rblSlots_1" type="radio" name="rblSlots" value="60" disabled="disabled" /><label for="rblSlots_1">1 Hour</label></span></td>
    </tr><tr>
    <td><span disabled="disabled"><input id="rblSlots_2" type="radio" name="rblSlots" value="90" disabled="disabled" /><label for="rblSlots_2">1 1/2 Hours</label></span></td>
    </tr><tr>
    <td><span disabled="disabled"><input id="rblSlots_3" type="radio" name="rblSlots" value="120" disabled="disabled" /><label for="rblSlots_3">2 Hours</label></span></td>
    </tr><tr>
    <td><span disabled="disabled"><input id="rblSlots_4" type="radio" name="rblSlots" value="150" disabled="disabled" /><label for="rblSlots_4">2 1/2 Hours</label></span></td>
    </tr><tr>
    ...etc...

in my form opener dialog i make an ajax post to grab some vaues from my webservice among them 'timespan' in the following javascipt, i have set timespan to a static variable for debugging, i want to enable the radio buttons which are <= timespan.

    var strTS = "30,60,90,120,150,180";
    var aryTS = strTS.split(",");
    var timespan = 120;

    for (i = 0; i <= 5; i++) {

        if ($('#rblSlots [value=' + aryTS[i] + ']').val() <= timespan) {

           $('#rblSlots [value=' + aryTS[i] + ']').removeAttr("disabled");

        }
    }

    $("#appointment-form").dialog("open");
    return false;

Upvotes: 1

Views: 1996

Answers (2)

user1457613
user1457613

Reputation: 115

After clearing caches in IE and Firefox, it came to be that the above code does indeed work in Firefox, but for some reason it would not in IE. So I abandoned the method, for one that gave me a more esthetic look anyway.

Abandoned the RadioButtonList for Radio Buttons in a table.
Gave unique class names and style='display:none;' to the rows containing the Radio's. and my javascript to:

    for (i = 0; i <= 5; i++) {
      if (aryTS[i] <= timespan) {
        $(".Slot_" + aryTS[i]).show();
      }
    } 

Works fine in IE and Firefox

Upvotes: 0

Ram
Ram

Reputation: 144719

you can use prop method:

$('#rblSlots input[value=' + timespan + ']').prop('disabled', false)

DEMO

Upvotes: 1

Related Questions