0

I've searched around and found multiple answers for this, but none of them have worked for me. I'm using a RadioButtonList inside a repeater control. Here is my jQuery function.

$("[name$='$PlanSelectionRbtnLst']").click(function () {
    alert($(this).val());  //this works
    $("[name$='$PlanSelectionRbtnLst']").find("input[value='-1']").attr("checked", true); // this doesn't
});

This is correctly alerting me the value I selected when I click on any radio button, but I am not able to change all of the RadioButtonList's selected button to the -1 value. If it matters, my script is in a master page.

EDIT: As requested, here a small snippet of the rendered html:

<table id="MainContent_BenefitsRpt_PlanSelectionRbtnLst_2>
<tbody>
    <tr>
        <td>
            <input name="ct100$MainContent$BenefitsRpt$ct103$PlanSelectionRbtnList" id="MainContent_BenefitsRpt_PlanSelectionRbtnLst_2_0_2" type="radio" value="9"/>
        </td>
    <tr>
</tbody>
proseidon
  • 2,235
  • 6
  • 33
  • 57

2 Answers2

1

checked in a binary property, not an attribute.

Try: .attr("checked", "checked")

But first, see if your selector is working:

alert($("[name$='$PlanSelectionRbtnLst']").find("input[value='-1']").length)
Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
  • For that I get '0'. Does that mean it found nothing? There should be 3 different radiobuttonlists (each containing the -1 value) that I want to change on click to the -1 value. – proseidon Aug 08 '12 at 18:38
  • Take a look here: http://stackoverflow.com/questions/4672229/jquery-radio-button-name-contains-string – Diodeus - James MacFarlane Aug 09 '12 at 14:31
0

Try this:

$("[name$='$PlanSelectionRbtnLst']").click(function () {
    $("[name$='$PlanSelectionRbtnLst']")
                    .find("input[value='-1']") 
                    .prop("checked", true); 
});
thecodeparadox
  • 86,271
  • 21
  • 138
  • 164