I using PHP in order to create an HTML form.
The form has 3 radio buttons and a submit button.
In the initial state of the form, none of the radio buttons is checked.
I want to make the form not to be submitted if non of the radio buttons is checked.
Is there any way to do that? I attached part of the PHP code.
for($i=0; $i<$nChoices; $i++) {
$Text='<input type="radio" name="answer" value="' . $IdChoices[$i] . '"';
$Text.="> ". $Choices[$i] . "</input>";
$choiceoutput.= $Text."<br /><br />";
}
Thanks!
This javascript can be used for simple client-side validation.
It’s not considered safe to only validate on the client-side
but if your purpose is to see if the user actually selected an value this will do. Otherwise further validation needs to be taking place in your php script.
Simple form for putting it to work.