views:

30

answers:

1

I have a collection_select field, and I want to make a div visible or invisible after changing it, depending on the new value.

I have the below code for the collection_select field, there is a JS function change_div_visibility which currently accepts a div name but I also want to pass in the collection_select value.

How can I also send the current value of the collection_select field to the change_div_visibility function?

<%= collection_select(:entry, :entry_status_id, EntStatus.find_all_draft_or_edit, :status, :en_desc, {}, {:onchange => "change_div_visibility('entry_set_editor')"}) %>

+1  A: 

The value of the <select> will be in this.value, so try this:

<%= collection_select(:entry, :entry_status_id,
    EntStatus.find_all_draft_or_edit, :status, :en_desc, {},
    { :onchange => "change_div_visibility('entry_set_editor', this.value)" })
%>
captaintokyo
perfect. Thank you! Appreciate the help from a fellow Japan dweller
nktokyo