# Save form values between submits

**URL:** <https://metaruby.com/t/save-form-values-between-submits/385>\
**Category:** Rails Forum\
**Created:** [November 10, 2015, 12:24pm UTC](https://metaruby.com/t/save-form-values-between-submits/385 "2015-11-10T12:24:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Viktor](https://metaruby.com/letter_avatar_proxy/v4/letter/v/d6d6ee/32.png) [@Viktor](https://metaruby.com/u/Viktor)\
**Post date:** [November 10, 2015, 12:24pm UTC](https://metaruby.com/t/save-form-values-between-submits/385/1 "2015-11-10T12:24:59Z")

</div>

Hello all. I need to save select tag values between form submits. There is the code snippet i have in my erb file:

```
  <%= form_tag(companies_path, { method: 'get' , id: 'select_type_form'}) do %>
    <%= select_tag 'company_type',
                options_from_collection_for_select(@company_types, 'id', 'name'),
                onchange: "$('#select_type_form').submit();" %>
  <% end %>

```

When user selects one of the values, an the page is being submitted and html table change its contents. Unfortunately after a form submit, select tag returns to its initial value, but i want it to display the value user has chosen before submit. Thank you.

---

<div class="post-metadata">

**Author:** ![Viktor](https://metaruby.com/letter_avatar_proxy/v4/letter/v/d6d6ee/32.png) [@Viktor](https://metaruby.com/u/Viktor)\
**Post date:** [November 10, 2015, 12:43pm UTC](https://metaruby.com/t/save-form-values-between-submits/385/2 "2015-11-10T12:43:40Z")

</div>

I think, I’ve found the solution - I added fourth arg to options\_from\_collection\_for\_select which is taken from the request params. Not sure if it is the right way, but it’s working:

```
<%= select_tag 'company_type',
            options_from_collection_for_select(@company_types, 'id', 'name', params[:company_type]),
            onchange: "$('#select_type_form').submit();" %>
```

---

<div class="post-metadata">

**Author:** ![danielpclark](https://metaruby.com/user_avatar/metaruby.com/danielpclark/32/823_2.png) [@danielpclark](https://metaruby.com/u/danielpclark)\
**Post date:** [November 10, 2015, 1:20pm UTC](https://metaruby.com/t/save-form-values-between-submits/385/3 "2015-11-10T13:20:05Z")

</div>

One thing I’ve experienced with Rails is that you can’t have forms overlap each other. For example if you have a bunch of rows with check boxes to select each row item… if that is implemented as a form, then you can’t have another form in it. I think that has to do with Rails deciphering which form is which. One solution is to write a JavaScript alternative to allow intermingling submission actions within a form.

I’ve written a gem that may interest you. [Dynaspan](https://github.com/danielpclark/dynaspan); with one method you can have a field that updates with the Rails server instantly upon any change. Currently permits a input field, text box, and drop-down option. It does it in the background so your page doesn’t reload and it leaves any form in the page untouched.

---

<div class="post-metadata">

**Author:** ![reggieb1](https://metaruby.com/user_avatar/metaruby.com/reggieb1/32/908_2.png) [@reggieb1](https://metaruby.com/u/reggieb1)\
**Post date:** [November 10, 2015, 2:48pm UTC](https://metaruby.com/t/save-form-values-between-submits/385/4 "2015-11-10T14:48:52Z")

</div>

That’s not a Rails limitation. It is an HTML one: [“There can be several forms in a single document, but the FORM element can’t be nested.”](http://www.w3.org/MarkUp/html3/forms.html).
