# Phoenix select input default value

**URL:** <https://forum.elixirforum.com/t/phoenix-select-input-default-value/7380>\
**Category:** Questions\
**Tags:** phoenix\
**Created:** [July 31, 2017, 8:23pm UTC](https://forum.elixirforum.com/t/phoenix-select-input-default-value/7380 "2017-07-31T20:23:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pedromvieira](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pedromvieira/32/5948_2.png) [@pedromvieira](https://forum.elixirforum.com/u/pedromvieira)\
**Post date:** [July 31, 2017, 8:23pm UTC](https://forum.elixirforum.com/t/phoenix-select-input-default-value/7380/1 "2017-07-31T20:23:31Z")

</div>

Is there a way to load a Phoenix select input with default value selected?

```
<%= form_for @conn, page_path(@conn, :index), [method: :post, as: :company], fn f -> %>

  <div class="form-group">
    <%= label f, :company, class: "control-label" %>
    <%= select f, :url,
      key_value_list,
      value: @conn.assigns.desired_value, class: "form-control" %>
    <%= error_tag f, :company %>
  </div>

  <div class="form-group">
    <%= submit "Go", class: "btn btn-primary" %>
  </div>

<% end %>

```

---

<div class="post-metadata">

**Author:** ![OvermindDL1](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/32/2677_2.png) [@OvermindDL1](https://forum.elixirforum.com/u/OvermindDL1)\
**Post date:** [July 31, 2017, 8:26pm UTC](https://forum.elixirforum.com/t/phoenix-select-input-default-value/7380/2 "2017-07-31T20:26:16Z")

</div>

Yep, it’s in the docs at: [Phoenix.HTML.Form — Phoenix.HTML v4.3.0](https://hexdocs.pm/phoenix_html/Phoenix.HTML.Form.html#select/4)

Basically just add a `selected: <value>` for whichever of the value’s should be default chosen. 🙂

---

<div class="post-metadata">

**Author:** ![pedromvieira](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pedromvieira/32/5948_2.png) [@pedromvieira](https://forum.elixirforum.com/u/pedromvieira)\
**Post date:** [July 31, 2017, 8:33pm UTC](https://forum.elixirforum.com/t/phoenix-select-input-default-value/7380/3 "2017-07-31T20:33:38Z")

</div>

Thanks.  
value: also worked.

---

<div class="post-metadata">

**Author:** ![OvermindDL1](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/32/2677_2.png) [@OvermindDL1](https://forum.elixirforum.com/u/OvermindDL1)\
**Post date:** [July 31, 2017, 10:37pm UTC](https://forum.elixirforum.com/t/phoenix-select-input-default-value/7380/4 "2017-07-31T22:37:14Z")

</div>

> [@pedromvieira](#):
>
> Thanks.  
> value: also worked.

Actually `value:` will override what is set to always specify this. `default:` will only specify what you put if the user has not already chosen one (like via params).

I.E:  
On first page load then default and value do the same.  
If refreshing the page (like submitting but an error happened or something) then default will not be set and whatever the user had set will remain, but if value is set then it will always override the user’s choice so they have to re-select. 🙂
