[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

uncheck, check RadioButton little javascript function

Posted on 2011-03-10
4
Medium Priority
?
551 Views
Last Modified: 2013-11-19
hi there,
I need a little function to work the following way:
I have two RadioButtons
<asp:RadioButton ID="rdYes" onClick="uncheckRadio()" runat="server" Text="Yes" Font-Names="Verdana, Arial, Helvetica" Font-Size="10pt" />
            <asp:RadioButton ID="rdNo" onClick="uncheckRadio()" runat="server" Text="No" Font-Names="Verdana, Arial, Helvetica" Font-Size="10pt" />

and what i need the function to do is when Yes is Checked then NO should be unchecked and vice versa. One RadioButton should be checked at the time.
I know a RadioButtonList will take care of this for me but i have some other events and i need them individually.
Thanks,
COHFL
           
0
Comment
Question by:COHFL
[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
  • 2
4 Comments
 
LVL 6

Expert Comment

by:Webmonkey
ID: 35095853
Try adding this:

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

Open in new window

0
 

Author Comment

by:COHFL
ID: 35095909
How do i call it?

OnClick="setCheckedValue(??,??)
0
 
LVL 6

Accepted Solution

by:
Webmonkey earned 1000 total points
ID: 35095974
Nevermind... this is better

<input id="rdYes" name="yes" type="radio" value="yes" onclick="document.getElementById('rdNo').checked = false;" />
<input id="rdNo" name="no" type="radio" value="no" onclick="document.getElementById('rdYes').checked = false;" />

Open in new window


0
 
LVL 82

Expert Comment

by:leakim971
ID: 35096389
You don't want to use RadioButtonList : http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobuttonlist(v=vs.80).aspx

Else why not use :
<input type="radio" name="yesorno" ID="rdYes" value="Yes" />Yes<br>
<input type="radio" name="yesorno" ID="rdNo" value="No" />No<br>

Open in new window

0

Featured Post

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

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

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

649 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