Validating radio button
Doing something meaningless is always a bad idea and a waste of developer and system time. Required is a HTML5 attribute for input control validation, you can add the required attribute at end of tag and if you want Gender radio button checked by default, you can add checked.
But yes, if it was not a radio button group then I completely agree with you on the PHP way to do this. :)Ok Smit, I have obviously wasted everyone's time here including my own. This would checked the radio button default when page loads, The required attribute is an HTML5 attribute and if you're using an older browser it may not support it.
It appears form validation does not include support for validating radio buttons so I have come up with a solution.
Nest your radio buttons into a field container with your default hidden input with an id you can target for validation: causes multiple prompts on every matched input.
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.
Otherwise I'm manually creating test cases for every bug I'm trying to evaluate & fix.Here is the code used for the radio button themselves.The creation of multiple groups of radio buttons for the one form is also straightforward.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.