Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

set all radio buttons to "No"

Posted on 2011-02-15
3
Medium Priority
?
312 Views
Last Modified: 2012-05-11
hi,

i have 5 radiobuttonlists - each containing a "Yes" and "No" option.

I can only have 1 "Yes" across all 5 lists, So when the user selects "Yes" in one of the lists - i want to reset all of the other Lists to "No".

I have the following code

//my click function on the 1st list
 $('#<%= radioButtonList1.ClientID %>').click(function() {

//if the click is a Yes
if ($('#<%= radioButtonList1.ClientID %>').find('input:radio:checked').val() == 1)
{
//then reset all other lists options to "NO" - (which is "0")
}
});

thanks


 
0
Comment
Question by:MrKevorkian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Assisted Solution

by:devlab2012
devlab2012 earned 1000 total points
ID: 34898737
Here is the complete working code of a .NET page:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script>
     function validate(sender)
     {
        var isYes = sender.value;
        if (isYes == "1")
        {
            var radioObj = document.getElementsByTagName("input");
            var radioLength = radioObj.length;
            for(var i = 0; i < radioLength; i++) 
            {
                if(radioObj[i].type == "radio")
                {
                    if (radioObj[i].name == sender.name)
                    {
                        continue;
                    }
                    if (radioObj[i].value == "0")
                    {
                        radioObj[i].checked = "checked";
                    }
                }
            }
         }
     }
    
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        List 1:
        <asp:RadioButtonList ID="RadioButtonList1" runat="server">
        <asp:ListItem Text="No" Value="0"></asp:ListItem>
        <asp:ListItem Text="Yes" Value="1" onclick="validate(this);"></asp:ListItem>
        </asp:RadioButtonList>
        <br />
        List 2:
        <asp:RadioButtonList ID="RadioButtonList2" runat="server">
        <asp:ListItem Text="No" Value="0"></asp:ListItem>
        <asp:ListItem Text="Yes" Value="1" onclick="validate(this);"></asp:ListItem>
        </asp:RadioButtonList>
        List 3:
        <asp:RadioButtonList ID="RadioButtonList3" runat="server">
        <asp:ListItem Text="No" Value="0"></asp:ListItem>
        <asp:ListItem Text="Yes" Value="1" onclick="validate(this);"></asp:ListItem>
        </asp:RadioButtonList>
        <br />
        List 4:
        <asp:RadioButtonList ID="RadioButtonList4" runat="server">
        <asp:ListItem Text="No" Value="0"></asp:ListItem>
        <asp:ListItem Text="Yes" Value="1" onclick="validate(this);"></asp:ListItem>
        </asp:RadioButtonList>
        List 5:
        <asp:RadioButtonList ID="RadioButtonList5" runat="server">
        <asp:ListItem Text="No" Value="0"></asp:ListItem>
        <asp:ListItem Text="Yes" Value="1" onclick="validate(this);"></asp:ListItem>
        </asp:RadioButtonList>
        <br />

    </div>
    </form>
</body>
</html>

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 1000 total points
ID: 34898759
Check this :

"Yes" radio button have value "1", "No" have "0"
You need to put the rblist in a div :
<div id="radioButtonsInside">

Open in new window

<%@ Page Title="Page d'accueil" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script language="javascript" type="text/javascript">
    $(document).ready(function () {
        $("input[type='radio'][value='1']", "#radioButtonsInside").click(function () {
            $("input[type='radio'][value='0']", "#radioButtonsInside").not( $(this).parents("table").find("input") ).attr("checked", "true");
        });
    });
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<div id="radioButtonsInside">
    <asp:RadioButtonList ID="RadioButtonList1" runat="server"><asp:ListItem Text="Yes" Value="1"></asp:ListItem><asp:ListItem Text="No" Value="0" Selected></asp:ListItem></asp:RadioButtonList>
    <asp:RadioButtonList ID="RadioButtonList2" runat="server"><asp:ListItem Text="Yes" Value="1"></asp:ListItem><asp:ListItem Text="No" Value="0" Selected></asp:ListItem></asp:RadioButtonList>
    <asp:RadioButtonList ID="RadioButtonList3" runat="server"><asp:ListItem Text="Yes" Value="1"></asp:ListItem><asp:ListItem Text="No" Value="0" Selected></asp:ListItem></asp:RadioButtonList>
    <asp:RadioButtonList ID="RadioButtonList4" runat="server"><asp:ListItem Text="Yes" Value="1"></asp:ListItem><asp:ListItem Text="No" Value="0" Selected></asp:ListItem></asp:RadioButtonList>
</div>
</asp:Content>

Open in new window

leakim971-409884.flv
0
 
LVL 1

Author Closing Comment

by:MrKevorkian
ID: 34918251
thanks very much guys, both excellent!
i like the video especially!  

leakim971 edged it slightly as it was less code.
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Geo-targeting is the practice of distributing content based on a person’s location, as best as you can determine it. Let’s look at some ways you could successfully use this tactic. The following tips and case studies could lead to meaningful results.
What monsters are hiding in your child's room? In this article I will share with you a tech horror story that could happen to anyone, along with some tips on how you can prevent it from happening to you.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question