Jump to content

Clearing Radios and Checkboxes


shadowayex

Recommended Posts

How do I clear radios and check boxes? I use document.getElementByName("name").value = ""; to empty text/password inputs and textareas, but how do you unset radios and check boxes?

Link to comment
Share on other sites

.checked=false; // Set either true or false the checked property

...a complete implementation is seen here:

<script type="text/javascript">var inps;window.onload=function(){inps=document.getElementsByTagName('input');for(var i=0;i<inps.length;i++){if(inps[i].type=='button'){inps[i].onclick=function(){for(var i=0;i<inps.length-1;i++){inps[i].checked=false; //This unchecks the checkbox/radioboxes. Set to true for the other way}}}}}</script><input type="checkbox"><input type="checkbox"><input type="checkbox"><input type="radio" name="myradio"><input type="radio" name="myradio"><input type="radio" name="myradio"><input type="checkbox"><input type="checkbox"><input type="checkbox"><input type="radio" name="myradio1"><input type="radio" name="myradio1"><input type="radio" name="myradio1"><br><input type="button" value="Unset">

You might find this link useful:http://www.quirksmode.org/js/forms.htmlHope it helps.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...