Skip to content

Instantly share code, notes, and snippets.

@haruta
Created March 31, 2011 05:37
Show Gist options
  • Save haruta/895868 to your computer and use it in GitHub Desktop.
Save haruta/895868 to your computer and use it in GitHub Desktop.
<html>
<head>
<script language="javascript" type="text/javascript">
window.onload = function(){
var elements = document.getElementsByTagName('label');
for (var i=0; i <elements.length; i++) {
elements[i].onclick = function(){
var radios = this.getElementsByTagName('input');
for (var j=0;j<radios.length;j++) {
if (radios[j].getAttribute('type').toLowerCase() == 'radio') {
radios[j].setAttribute('checked','checked');
}
}
}
}
}
</script>
</head>
<body>
<form>
<label>radio label: <input type="radio" value="1" name="radio" /></label>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment