Click here to Skip to main content
14,297,332 members
Rate this:
Please Sign up or sign in to vote.
See more:
This is my code but its not working

I have Radiobutton id id
ID="RadioSecC1"
I want that on clicking on checkbox

I have another Radiobutton id is
id="RadioTier2Act1"
it should be selected if i have selected previous one and if earlier is not selected then second one remain unselected
$('#<%=ChkSameAstier1.ClientID%>').on("click", function () {

              if ($(this).is(":checked")) {
                  var Rdb1 = $('#<%=RadioSecC1.ClientID %>').val();
                  $('#<%=RadioTier2Act1.ClientID %>').val(Rdb1);
Posted
Updated 31-Oct-13 0:51am
v2
Comments
IpsitaMishra 31-Oct-13 6:33am
   
can you please clarify you question,so that it will be easier to answer.
Member 10310320 31-Oct-13 6:43am
   
I Have Radio Button
Id= "RadioSecC1"
if i select this radio button then

I want that on clicking on checkbox
i have another radio button ,
Id="RadioTier2Act1"
is should be selected
IpsitaMishra 31-Oct-13 6:56am
   
You mean that On clicking the first Radio Button and check box your second radio button should be selected.
IpsitaMishra 31-Oct-13 6:56am
   
If possible can you please paste your html content.
Member 10310320 31-Oct-13 7:01am
   
<div style="width: 20%; height: 460px; border: 1px solid black; float: left">
<div style="width: 100%; height: 50px; border: 1px solid black; float: left">
Please tick only one
</div>
<div style="width: 100%; height: 50px; border: 1px solid black; float: left">
<asp:RadioButton ID="RadioSecC1" GroupName="PFM" runat="server" />
</div>
<div style="width: 100%; height: 50px; border: 1px solid black; float: left">
<asp:RadioButton ID="RadioSecC2" GroupName="PFM" runat="server" />
</div>
<div style="width: 100%; height: 50px; border: 1px solid black; float: left">
<asp:RadioButton ID="RadioSecC3" GroupName="PFM" runat="server" />
</div>
<div style="width: 100%; height: 50px; border: 1px solid black; float: left">
<asp:RadioButton ID="RadioSecC4" GroupName="PFM" runat="server" />
</div>
<div style="width: 100%; height: 50px; border: 1px solid black; float: left">
<asp:RadioButton ID="RadioSecC5" GroupName="PFM" runat="server" />
</div>
<div style="width: 100%; height: 50px; border: 1px solid black; float: left">
<asp:RadioButton ID="RadioSecC6" GroupName="PFM" runat="server" />
</div>
<div style="width: 100%; height: 50px; border: 1px solid black; float: left">
<asp:RadioButton ID="RadioSecC7" GroupName="PFM" runat="server" />
</div>
<div style="width: 100%; height: 50px; border: 0px solid black; float: left">
<asp:RadioButton ID="RadioSecC8" GroupName="PFM" runat="server" />
</div>
</div>
If same as Tier I, Please Tick
<asp:CheckBox ID="ChkSameAstier1" runat="server" />

<div style="width: 100%; height: 50px; border: 1px solid black; float: left">
<asp:RadioButton ID="RadioTier2Act1" GroupName="PMFtier2" runat="server" />
</div>
<div style="width: 100%; height: 50px; border: 1px solid black; float: left">
<asp:RadioButton ID="RadioTier2Act2" GroupName="PMFtier2" runat="server" />
</div>
<div style="width: 100%; height: 50px; border: 1px solid black; float: left">
<asp:RadioButton ID="RadioTier2Act3" GroupName="PMFtier2" runat="server" />
</div>
<div style="width: 100%; height: 50px; border: 1px solid black; float: left">
<asp:RadioButton ID="RadioTier2Act4" GroupName="PMFtier2" runat="server" />
</div>
<div style="width: 100%; height: 50px; border: 1px solid black; float: left">
<asp:RadioButton ID="RadioTier2Act5" GroupName="PMFtier2" runat="server" />
</div>
<div style="width: 100%; height: 50px; border: 1px solid black; float: left">
<asp:RadioButton ID="RadioTier2Act6" GroupName="PMFtier2" runat="server" />
</div>
<div style="width: 100%; height: 50px; border: 1px solid black; float: left">
<asp:RadioButton ID="RadioTier2Act7" GroupName="PMFtier2" runat="server" />
</div>
&

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You need to set the value of the second radio button with
.prop()
instead of val().

What I've also done in this solution is generalize it to handle whichever of the Tier1 radio buttons is selected. The path you started down would necessitate separate code for each possible selection, since you were getting and setting values down at the individual radio button level.

$('#<%=ChkSameAstier1.ClientID%>').on("click", function () {
    if ($(this).is(":checked")) {
        var tier1 = $('input[name=PFM]:checked').val();
        $('input[name=PMFtier2][value=' + tier1 + ']').prop('checked', true);
    }
});
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100