Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to toggle radio buttons on a web page

Posted on 2008-10-23
9
Medium Priority
?
1,295 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 1000 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

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 1000 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

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

715 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