Javascript code for validating radio buttons

Rated 3.82/5 based on 987 customer reviews

roughly my html looks like: Thank you for your interest in this question.Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).This way, the form will also keep its previous data.I've combed a ton of the pages on here, and still am incapable to get my explicit validator to work.The setup and validation of radio buttons appears to be the form field that gives many webmasters the most difficulty in setting up.In actual fact the setup of these fields is the most simple of all form fields to validate as radio buttons set one value that only needs to be tested when the form is submitted.The name field determines which group that a particular button belongs to.

The following function will validate that one of the radio buttons in a group has been selected: To use the above function, call it from within your form validation routine and pass it the radio button group name.Can only use HTML CSS and Java Script for this, I know it's 1000 times easier in jquery but sadly I can't use that.And I know my HTML isn't valid, but unless it directly affects my current problem then I'll handle it later.Basically, when the submit button is clicked, I want the script to verify a radio is checked, if one is checked to do nothing.If one isn't checked I want it to post an alert message.

Leave a Reply