Hi,

Is there any possible way to unselect a number of radiobuttons grouped in the same groupname?

Thank you

I use another radio button

<input type='radio' value="1" name="samename" >5<br>
<input type='radio' value="2" name="samename" >4<br>
<input type='radio' value="3" name="samename" >3<br>
<input type='radio' value="4" name="samename" >2<br>
<input type='radio' value="5" name="samename" >1<br>
<input type='radio' value="" name="samename" checked>Reset<br>

sorry, can you explain more please?

sorry, can you explain more please?

look at the html sample given, copy it to a html file on your desktop and run it
the reset button will uncheck any other button in the list
and give a nul value, so that verification of submitted data can still take place

There is no button in your code ! Maybe you're talking about the reset radiobutton.

What I'm looking for is the following:
I have 2 groupnames, each one has many radiobuttons. When I select a radiobutton from the 1st groupname (group1), it must unselect all radiobuttons in the 2nd groupname (group2). I tried this code but it's not working

foreach (RadioButton btn in this.Controls)
        {
            //Do some commands
        }

Also I tried this but it's not working

protected void Button1_Click(object sender, EventArgs e)
    {
    //http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_20987249.html
        
        foreach (Control btn in this.Controls)
        {
            if (btn is System.Web.UI.WebControls.RadioButton)
            {
                //Do some commands
                //TextBox1.Text += ((RadioButton)btn).Text + "<br>";
            }
        }

        foreach (RadioButton btn in this.Controls)
        {
             //Do some commands
        }
    }

that has little relation to the question first asked,
stipulated same groupname,
gone to examine some code,
post when i have an answer
dos vdanye

Hi,

Is there any possible way to unselect a number of radiobuttons grouped in the same groupname?

Thank you

Try this javascript function to uncheck all radiobuttons with the same groupname.

function unSelectAllCheckBoxes()
{
	var rdoBtns_Array = document.getElementsByTagName('input');
	
	if(rdoBtns_Array.length>0)
	{
		for(i=0; i<rdoBtns_Array.length; i++)
		{
			//Check for radio button with groupname 'myGroupName'
			if((rdoBtns_Array[i].type == 'radio') && (rdoBtns_Array[i].name == 'myGroupName'))
			{
				//Uncheck Radio Button
				rdoBtns_Array[i].checked = false;

			}
		}
	}

}

Thank you Aneesh_Argent.

Try this javascript function to uncheck all radiobuttons with the same groupname.

Your answer confirm that it's impossible to unselect a given group of radiobuttons in a single instruction (like ClearSelection() of the RadioButtonList) !
I'm not familiar to Javascript. I'm newbie to aspx. At the moment, this solution is working for me:

protected void RadioButton_CheckedChanged(string groupname, string buttonlistname)
    {
        foreach (Control ctrl in form1.Controls)
        {
            if (ctrl is System.Web.UI.WebControls.RadioButton)
            {
                
                RadioButton btn = (RadioButton)ctrl;

                if (btn.GroupName != groupname)
                    btn.Checked = false;
            }
            else if (ctrl is System.Web.UI.WebControls.RadioButtonList)
            {
                RadioButtonList btn = (RadioButtonList)ctrl;

                if (btn.ID != buttonlistname)
                    btn.ClearSelection();
            }
        }
    }

and I'm calling this function from any RadioButton or RadioButtonList Checked Changed as follows:

protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
    {
        RadioButton_CheckedChanged(RadioButton2.GroupName, "none");
    }
    protected void RadioButton3_CheckedChanged(object sender, EventArgs e)
    {
        RadioButton_CheckedChanged(RadioButton3.GroupName, "none");
    }
...
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        RadioButton_CheckedChanged("none", RadioButtonList1.ID);
    }

Thank you almostbob

that has little relation to the question first asked,

Maybe, but i was looking for an instruction that may permit the unselection of a number of groupnames, without using the foreach ALL CONTROLS.

one group precludes the other
is it possible to use a single name and divide the response to the buttons by group, at form validation
example perhaps
ignoring syntax punctuation and styling, trying something brain not 100%

<table><tr>
<td>
<input type=radio name=groupname value=A1>a1
<input type=radio name=groupname value=A2>a2
<input type=radio name=groupname value=A3>a3
<input type=radio name=groupname value=A4>a4
<input type=radio name=groupname value=A5>a5
<input type=radio name=groupname value=A6>a6
</td><td>
<input type=radio name=groupname value=b1>B1
<input type=radio name=groupname value=b2>B2
<input type=radio name=groupname value=b3>B3
<input type=radio name=groupname value=b4>B4
<input type=radio name=groupname value=b5>B5
<input type=radio name=groupname value=b6>B6
<input type=radio name=groupname value=b7>B7
</td></tr></table>

when the form is submitted parse the response by first character, if (function defined elsewhere) firstchar = b do something if (function defined elsewhere) firstchar = a do something different any response in group B unchecks all responses in group A
any response in group A unchecks all in group B

another option
after radio buttons are selected there is no way to unselect them all, a hidden nul value button may work if the forms cannot share a name and be poarsed on validation
please igonre syntax errors,

as the first radio button in a group
<input type=radio style='visibility:hidden' name=groupa value=">
<input type=radio name='groupa' onselect="document.groupb[0].checked;" value='a1>a1
<input type=radio name='groupa' onselect="document.groupb[0].checked;" value='a2>a2
<input type=radio name='groupa' onselect="document.groupb[0].checked;" value='a3>a3

buttons in group.b

<input type=radio style='visibility:hidden' name=groupb value="">
<input type=radio name='groupb' onselect="document.groupa[0].checked;" value='B1>B1
<input type=radio name='groupb' onselect="document.groupa[0].checked;" value='B2>B2
<input type=radio name='groupb' onselect="document.groupa[0].checked;" value='B3>B3

still not 'good' ideas

onselect="document.groupa[0].checked;"

onselect="document.groupa[0].checked=true;"

getting sloppy
sorry

You can also add the input button (btnDeleteSelection) and use this javascript code to deselect all items in radio button list:

$("#btnDeleteSelection").click(function() {
$('#<%=radioButtonList.ClientID %> input[type=radio]:checked').removeAttr("checked");
return false;
});

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.