How can I set the default value for an HTML ltselectgt element

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I thought that adding a "value" attribute set on the <select> element below would cause the <option> containing my provided "value" to be selected by default:

<select name="hall" id="hall" value="3">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
</select>

However, this did not work as I had expected. How can I set which <option> element is selected by default?

Answers

Set selected="selected" for the option you want to be the default.

<option selected="selected">
3
</option>

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/3518002/how-can-i-set-the-default-value-for-an-html-select-element

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils