You can use the property required as its a boolean attribute that solve ur problem. required="required"
How to require radio button selection in html5 form
-
11-06-2023 - |
Question
html 5 form contains two radio buttons. How to force user to select one radion button before submitting form ? I tried to use required but there is not radio button group, required shoult applited to group.
<form action="/Home/Sendtitle" method="post">
<p>
Title* <span>
<span>
<span>
<input name="staatus" type="radio" value="Mister" autofocus>
<span>Mister</span>
</span>
<span>
<input name="staatus" type="radio" value="Missis">
<span>Missis</span>
</span>
</span>
</span>
</p>
<p>
<input type="submit" value="Send title" >
</p>
</form>
Solution 3
OTHER TIPS
Use required
attribute.
<input name="staatus" type="radio" value="Missis" required>
You just need to set the required-attribute for one input of the radiogroup, but you can set it for all.
<form action="/Home/Sendtitle" method="post">
<p>
Title* <span>
<span>
<span>
<input name="staatus" type="radio" value="Mister" autofocus required>
<span>Mister</span>
</span>
<span>
<input name="staatus" type="radio" value="Missis">
<span>Missis</span>
</span>
</span>
</span>
</p>
<p>
<input type="submit" value="Send title" >
</p>
</form>
And you can use it once:
<span>
<input name="status" type="radio" value="Mister" autofocus required="required">
<span>Mister</span>
</span>
<span>
<input name="status" type="radio" value="Missis">
<span>Missis</span>
</span>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow