Solved

set all radio buttons to "No"

Posted on 2011-02-15
3
307 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 250 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 250 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Scroll through Images 2 185
JavaScript issue with comma separated values 12 77
hide show div element in asp.net 3 86
script for sleep and wakeup on PC 2 149
Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime is disastrous for companies and can lead to major hits on a brand, reputation, an…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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