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>&nbsp;
        <span>Mister</span>
      </span>
      <span>
        <input name="staatus" type="radio" value="Missis">&nbsp;
        <span>Missis</span>
      </span>
    </span>
  </span>
</p>

<p>
  <input type="submit" value="Send title" >
</p>

</form>
Was it helpful?

Solution 3

You can use the property required as its a boolean attribute that solve ur problem. required="required"

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>&nbsp;
        <span>Mister</span>
      </span>
      <span>
        <input name="staatus" type="radio" value="Missis">&nbsp;
        <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">&nbsp;
    <span>Mister</span>
  </span>
  <span>
    <input name="status" type="radio" value="Missis">&nbsp;
    <span>Missis</span>
  </span>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top