Skip to content

Instantly share code, notes, and snippets.

@marklocklear
Created October 27, 2011 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marklocklear/1319503 to your computer and use it in GitHub Desktop.
Save marklocklear/1319503 to your computer and use it in GitHub Desktop.
<%= submit_tag 'Submit', :onclick => 'return validate(this)' %><br/>
<script type="text/javascript" charset="utf-8">
function validate() {
var valid = false;
var radio_groups = {}
$(":radio").each(function(){
radio_groups[this.name] = true;
})
for(group in radio_groups){
if (!!$(":radio[name="+group+"]:checked").length) {
valid = true;
}
}
if (!valid) {
alert('you forgot to check a radio button somewhere');
return false;
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment