Link to home
Start Free TrialLog in
Avatar of Denis Orozco
Denis OrozcoFlag for United States of America

asked on

uncheck, check RadioButton little javascript function

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
           
Avatar of Webmonkey
Webmonkey
Flag of United States of America image

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

Avatar of Denis Orozco

ASKER

How do i call it?

OnClick="setCheckedValue(??,??)
ASKER CERTIFIED SOLUTION
Avatar of Webmonkey
Webmonkey
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of leakim971
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