Solved

How to toggle radio buttons on a web page

Posted on 2008-10-23
9
1,293 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 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