Solved

How to toggle radio buttons on a web page

Posted on 2008-10-23
9
1,289 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
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 …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

19 Experts available now in Live!

Get 1:1 Help Now