Is there a way to define a default value to be selected in an HTML Form of Radio Buttons?

wide_eyed_pupil picture wide_eyed_pupil · Jan 23, 2012 · Viewed 27.1k times · Source
<body>
  <form>
    <input type="radio" name="amount" value="10"/> $10&#8194 
    <input type="radio" name="amount" value="25"/> $25&#8194 
    <input type="radio" name="amount" value="50"/> $50&#8194
    <input type="radio" name="amount" value="100"/> $100&#8194
    <input type="radio" name="amount" value="250"/> $250&#8194
    <input type="radio" name="amount" value="other"/> Other
  </form>
</body>

To make the $50 option the default selection what HTML code would I use?

Link to code bin demo

Answer

stealthyninja picture stealthyninja · Jan 23, 2012

Just set it as checked:

<body>
  <form>
    <input type="radio" name="amount" value="10"/> $10&#8194 
    <input type="radio" name="amount" value="25"/> $25&#8194 
    <input type="radio" name="amount" value="50" checked="checked" /> $50&#8194
    <input type="radio" name="amount" value="100"/> $100&#8194
    <input type="radio" name="amount" value="250"/> $250&#8194
    <input type="radio" name="amount" value="other"/> Other
  </form>
</body>