Code for validating radio button in javascript

See HTML5: How to use the "required" attribute with a "radio" input field for more information on how to do this well. 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).

Would you like to answer one of these unanswered questions instead?

The creation of multiple groups of radio buttons for the one form is also straightforward.

All you need to do is to provide the second group of radio buttons with a different name to that used for the first group.

If you have suggestions for other approaches, or additional questions related to this example, be sure to email me. For more information, you'll want to keep a good Java Script reference manual handy.

Microsoft is conducting an online survey to understand your opinion of the Msdn Web site.

On a side note, I'll disagree with the blanket statement that you should check a radio button by default.And I know my HTML isn't valid, but unless it directly affects my current problem then I'll handle it later.I would change the line if (radios[i].checked) form Valid = true; to if (radios[i].checked) so it becomes true with the value of the checked item. Also, always use braces, even if there is just one item. when submit button is pressed and no radio buttons have been selected, it alerts the user saying 'please select a check box', and if a radio button has been selected then simply submit the form, needs no alert.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.If one isn't checked I want it to post an alert message.

595

Leave a Reply