# Drop down not keeping value after errors are shown

**URL:** <https://www.ruby-forum.com/t/drop-down-not-keeping-value-after-errors-are-shown/130855>\
**Category:** Rails\
**Created:** [March 3, 2008, 11:50pm UTC](https://www.ruby-forum.com/t/drop-down-not-keeping-value-after-errors-are-shown/130855 "2008-03-03T23:50:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [March 3, 2008, 11:50pm UTC](https://www.ruby-forum.com/t/drop-down-not-keeping-value-after-errors-are-shown/130855/1 "2008-03-03T23:50:49Z")

</div>

My drop down gets reset to the first value when the form gets returned  
with errors.

here is my code:

\<%= f.select :card\_type, [  
[‘Choose a Payment Type’, nil],  
[‘Visa’, ‘Visa’],  
[‘MasterCard’, ‘master’],  
[‘American Express’, ‘American Express’]] %\>

For example, say the user selects “Visa” and doesn’t fill out the rest  
of the form correctly. The user submits the form and errors are shown.  
For some reason this drop down does not keep the “Visa” value and goes  
back to the “Choose a Payment Type”.

How can i keep the value in the drop down after errors are shown?

---

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [March 4, 2008, 12:00am UTC](https://www.ruby-forum.com/t/drop-down-not-keeping-value-after-errors-are-shown/130855/2 "2008-03-04T00:00:19Z")

</div>

have you tried logging the value of @my\_obj.card\_type to see what it  
returns?

Mike

---

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [March 4, 2008, 12:18am UTC](https://www.ruby-forum.com/t/drop-down-not-keeping-value-after-errors-are-shown/130855/3 "2008-03-04T00:18:22Z")

</div>

Mike G. wrote:

> have you tried logging the value of @my\_obj.card\_type to see what it  
> returns?
> 
> Mike

that value gets sent over the wire correctly, but it doesn’t come back  
up if the form had errors.

---

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [March 4, 2008, 7:10am UTC](https://www.ruby-forum.com/t/drop-down-not-keeping-value-after-errors-are-shown/130855/4 "2008-03-04T07:10:24Z")

</div>

post your code
