Solved

How to toggle radio buttons on a web page

Posted on 2008-10-23
9
1,288 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
  • 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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now