Solved

uncheck, check RadioButton little javascript function

Posted on 2011-03-10
4
542 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
  • 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 250 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
arrays and buttons with user input 2 34
Echo'd values in dropdowns 6 30
Two decimal 5 29
How to show popup no matter what a user clicks on navigation wise 10 35
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
This article discusses how to implement server side field validation and display customized error messages to the client.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

726 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