Solved

How to toggle radio buttons on a web page

Posted on 2008-10-23
9
1,292 Views
Last Modified: 2013-12-17
Greetings:

I'm trying to modify a web page developed by somebody else.  I noticed two radio buttons don't toggle from 'Yes' to 'No' as they should.

There are other Yes/No radio buttons on the page that work but there doesn't seem to be any associated code - they just work automatically as they should.  

The picture below shows the two I'm working with.  I'm sure it doesn't help much.

Anyway, the code applies to new users that need a phone.  I added this code to make the radio buttons work as they should but both can still be selected at the same time (no toggle):

 protected void CBAvailablePhone_CheckedChanged(object sender, EventArgs e)
    {
        if (CBNeedPhone.Checked = true)
            CBNeedPhone.Checked = false;
    }
    protected void CBNeedPhone_CheckedChanged(object sender, EventArgs e)
    {
        if (CBAvailablePhone.Checked = true)
            CBAvailablePhone.Checked = false;
    }

Any ideas?
Thanks!
new-user.JPG
0
Comment
Question by:John500
[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
  • 5
  • 3
9 Comments
 
LVL 7

Expert Comment

by:ASPSQLServerCOM
ID: 22788409
is this radio button are in group, could you please paste the browser HTML code (view source) of the page
0
 

Author Comment

by:John500
ID: 22788496
There probably is not a group for these two.  The first bit of code below is for a set of buttons that does work, the next block is for the ones that don't.

Thanks
Token question:
------------------
<tr>
		<td colspan="3" rowspan="2" style="height: 35px" valign="middle"> &nbsp;- Is there any available token in your ...?</td>
		<td style="height: 35px" valign="bottom">
                <input id="ctl00_master_RBAvailableToken" type="radio" name="ctl00$master$TokenAvailable" value="RBAvailableToken" tabindex="15" /><label for="ctl00_master_RBAvailableToken">Yes, Enter token number: </label>
            </td>
		<td style="height: 35px" valign="bottom">
                <input name="ctl00$master$TBTokenAvailabe" type="text" id="ctl00_master_TBTokenAvailabe" tabindex="16" style="border-style:Groove;width:240px;" />
            </td>
	</tr>
 
Phone question:
------------------
<tr>
		<td colspan="3" rowspan="2" valign="middle">
                &nbsp;Is there a working &nbsp;telephone on the new user's desk?</td>
		<td>
                <span style="display:inline-block;width:47px;"><input id="ctl00_master_CBAvailablePhone" type="radio" name="ctl00$master$CBAvailablePhone" value="CBAvailablePhone" tabindex="21" /><label for="ctl00_master_CBAvailablePhone">Yes</label></span>
            </td>
		<td>
                &nbsp;</td>
	</tr>
	<tr>
		<td colspan="2" style="height: 20px">
                <span style="display:inline-block;width:44px;"><input id="ctl00_master_CBNeedPhone" type="radio" name="ctl00$master$CBNeedPhone" value="CBNeedPhone" tabindex="22" /><label for="ctl00_master_CBNeedPhone">No</label></span>
            </td>
	</tr>

Open in new window

0
 
LVL 10

Accepted Solution

by:
Bane83 earned 250 total points
ID: 22788531
As ASPSQLServerCOM mentioned, a GroupName is required for the radio buttons to use this group functionality.

Remove the javascript you've placed onto the radio buttons and add something along the lines of:
GroupName="NeedsPhone"
to both RadioButtons.

An alternative for future consideration is using a RadioButtonList rather than individual radio buttons:
<asp:RadioButtonList ID="rbl" runat="server" RepeatDirection="Vertical">
     <asp:ListItem Text="Yes" Value="1"></asp:ListItem>
     <asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:RadioButtonList>

In code behind, you get the value from this like so:
rbl.SelectedValue
which returns a string equivalent to the value of the selected radiobutton.  This control does automatic grouping so that you don't have to bother.
0
Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

 

Author Comment

by:John500
ID: 22788904
I'm still not getting it.  Please take a look at the example below.  What would make the first set of radio buttons work over the second.

It does appear the second set of radio buttons belongs to a group.

In the case of the first set, what is it exactly in the code that causes them to work??


new-user.JPG
0
 

Author Comment

by:John500
ID: 22788907
Here is the code I forgot:


<tr>
		<td colspan="3" rowspan="2"> &nbsp;- Is there any available computer in your department or office for this new user?</td>
		<td valign="middle">
                <input id="ctl00_master_RBAvailableMachine" type="radio" name="ctl00$master$MachineAvailable" value="RBAvailableMachine" onclick="javascript:setTimeout('__doPostBack(\'ctl00$master$RBAvailableMachine\',\'\')', 0)" tabindex="12" /><label for="ctl00_master_RBAvailableMachine">Yes, Select tag number: </label></td>
		<td valign="middle">
                <select name="ctl00$master$DDTagAvailable" onchange="javascript:setTimeout('__doPostBack(\'ctl00$master$DDTagAvailable\',\'\')', 0)" id="ctl00_master_DDTagAvailable" disabled="disabled" tabindex="13" style="width:245px;border-style: groove">
 
		</select>
                </td>
	</tr>

Open in new window

0
 

Author Comment

by:John500
ID: 22788923
... and I forgot this code which goes below the java script in my last post
<tr>
		<td style="height: 22px">
                <input id="ctl00_master_RBNeedSystem" type="radio" name="ctl00$master$MachineAvailable" value="RBNeedSystem" checked="checked" tabindex="14" /><label for="ctl00_master_RBNeedSystem">No, And I need a new machine </label>
            </td>
		<td>&nbsp;</td>
	</tr>

Open in new window

0
 
LVL 7

Expert Comment

by:ASPSQLServerCOM
ID: 22789065
hi, could you please post the total HTML and javascript
0
 
LVL 7

Assisted Solution

by:ASPSQLServerCOM
ASPSQLServerCOM earned 250 total points
ID: 22789144
hi, check your code

the radio button name is not same for both the radio button
it is
name="ctl00$master$CBAvailablePhone"
and other is
 name="ctl00$master$CBNeedPhone"

make it same and its all done for you
0
 

Author Closing Comment

by:John500
ID: 31509307
Thanks
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 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