# Retrieve selected value from \<%=select()%\>

**URL:** <https://www.ruby-forum.com/t/retrieve-selected-value-from-select/150313>\
**Category:** Rails\
**Created:** [October 7, 2008, 7:13am UTC](https://www.ruby-forum.com/t/retrieve-selected-value-from-select/150313 "2008-10-07T07:13:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 7, 2008, 7:13am UTC](https://www.ruby-forum.com/t/retrieve-selected-value-from-select/150313/1 "2008-10-07T07:13:35Z")

</div>

Hi, I’m learning ruby on rails at the moment so please consider if this  
is a silly problem. I have a index.rhtml file where the combo box lies.  
When this combo box with different areas changes it updates another  
combo box within the same file and displays all the campsites in that  
area. For this I’ve written:

## index.rhtml
 \<%= select(:selected, :location, GreatWalk.getAvailableLocations, {:prompt =\> 'Select a category'}, :id =\> :id\_selected) %\>

\<%= observe\_field :id\_selected, :url =\> {:action =\>  
:update\_campsites}, :update =\> :campsites, :with =\> “walk\_id” %\>

\<%form\_for :booking, :url =\> {:action =\> :save\_bookings} do |form|%\> 
 \<%=form.select "camp\_id", Campsite.getAvailableCamps%\> 
 \<%=submit\_tag "Get Camp And Save"%\> \<%end%\> --------------------------------------------------------------------------------
## update\_campsites.rhtml

 \<%=select "selected", "camp\_id", @campholder %\>
--------------------------------------------------------------------------------

The problem is, no way in the world, I could get the selected campsite.  
I tried @booking=Booking.new(params[:booking]) and then (print  
@booking.camp\_id) in the save\_bookings action in the controller, it  
shows nil. I also tried putting @camp=params[“selected”][“camp\_id”] and  
then (print @camp )in update\_campsites action in controller but gives  
error instead. Also after I click the button and change the first combo  
box value it doesn’t trigger any update to the second combo box. So,  
please help me find what I’m doing wrong here and how I can get that  
selected value, that would be so great. thanks

regards,  
Jay
