# How to get the value of dropdown box selected using collect\_select()?

**URL:** <https://www.ruby-forum.com/t/how-to-get-the-value-of-dropdown-box-selected-using-collect-select/156401>\
**Category:** Rails\
**Created:** [December 26, 2008, 6:38pm UTC](https://www.ruby-forum.com/t/how-to-get-the-value-of-dropdown-box-selected-using-collect-select/156401 "2008-12-26T18:38:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![srikanth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f9ae1b/32.png) [@srikanth](https://www.ruby-forum.com/u/srikanth)\
**Post date:** [December 26, 2008, 6:38pm UTC](https://www.ruby-forum.com/t/how-to-get-the-value-of-dropdown-box-selected-using-collect-select/156401/1 "2008-12-26T18:38:41Z")

</div>

Hi,

I am trying to get the value of ‘contenttype\_id’ value from the  
‘streams’ table like:

\<%= collection\_select  
(:stream, :contenttype\_id,@contenttypes,:id,:name),{},{onchange =\>  
“switchdiv(value)”;}%\>

here i want to recieve the vaule of selected option in switchdiv( ) as  
argument.  
my collection\_select dropdown box contain names as video,audio,image  
and speech with having values as 1,2,3 and 4 respectively.

so if i hardcoded as value = 1 in switchdev() function like  
switchdiv(1) am able do functionality what i implemented in switchdiv  
function,

instead of hardcdoing i want to get the “value” of “name” from  
dropdownbox.  
ex:if i select name as ‘video’ i shoud get the value as ‘1’  
can anyone give idea to get the value from collect\_select?  
thanks  
Srikanth

---

<div class="post-metadata">

**Author:** ![srikanth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f9ae1b/32.png) [@srikanth](https://www.ruby-forum.com/u/srikanth)\
**Post date:** [December 26, 2008, 8:52pm UTC](https://www.ruby-forum.com/t/how-to-get-the-value-of-dropdown-box-selected-using-collect-select/156401/2 "2008-12-26T20:52:18Z")

</div>

On 26 Dec 2008, at 17:37, srikanth wrote:

> here i want to recieve the vaule of selected option in switchdiv( ) as  
> ex:if i select name as ‘video’ i shoud get the value as ‘1’  
> can anyone give idea to get the value from collect\_select?  
> thanks

switchdiv($F(‘id\_of\_the\_select\_tag’)) will do the trick if you have  
prototype library loaded

Fred
