Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checkbox to wipe out radiobuttons 1

Status
Not open for further replies.

Sniipe

Programmer
Oct 9, 2006
115
IE
Code:
		<tr>
			<td>Are you happy?</td>
			<td><input type="radio" name="2"  value="4" can_run="true"/></td>
			<td>Yes</td>
			<td><input type="radio" name="2"  value="5" can_run="true"/></td>
			<td>No</td>
			<td><input type="checkbox" name="2" checked/></td>
		</tr>
I'm creating the above code dynamically. What would I have to enter for an onclick so that when the checkbox is ticked that the yes/no radio button would be unticked (currently above it shows neither radiobutton checked)
 
Sadly there is no clearing function of that nature, you would need to create your own.

But if done correctly you can use it with all your radio buttons, regardless of how many each same-named group may have.

Code:
<script>
function ClearRadios(radios_name){
var radios=document.getElementsByName(radios_name);

for(var i=0; i<=radios.length-1; i++){

radios[i].checked=false;
}


}

</script>


<input type="checkbox" name="2" checked/ onClick="ClearRadios('2');">

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
cool, thanks Phil,

Its good but I think I need it to only work for radio buttons. Can I get getElementsByName and then dig down into that and get them by type?
 
Sure, you can look for the ones who's type is radio.

Code:
for(...)
  if(radios[i].type=='radio'){
    radios[i].checked=false;
  }

}

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top