Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

<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

like image 829
wide_eyed_pupil Avatar asked Jan 23 '12 06:01

wide_eyed_pupil


2 Answers

Just simply add

checked="checked"

in a declaration of button which you want to be default checked.

like image 34
Bhavin Vora Avatar answered Oct 17 '22 00:10

Bhavin Vora


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>
like image 181
stealthyninja Avatar answered Oct 17 '22 00:10

stealthyninja