# Getting Data From A Select Menu

**URL:** <https://www.ruby-forum.com/t/getting-data-from-a-select-menu/47525>\
**Category:** Rails\
**Created:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/getting-data-from-a-select-menu/47525 "2005-11-12T12:49:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nmealey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7cd45c/32.png) [@nmealey](https://www.ruby-forum.com/u/nmealey)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/getting-data-from-a-select-menu/47525/1 "2005-11-12T12:49:19Z")

</div>

I am using a select menu to allow people to pick an item and be taken to  
a new page containing that item’s data. Pretty straightforward stuff.  
Except that I cannot quite figure out how to do this in Rails.

I do not understand how to grab the variable from the select menu. With  
the code I am using, I cannot get the data into the mysql query.

Can someone point me in the right direction?

This is the code for the select menu (it uses an array of arrays in the  
model file):

\<%= start\_form\_tag :action =\> ‘history’ %\>

| \<%= options = [["Select client", ""]] + Notification::CLIENTS

select(“notification”, “client”, options) %\>

 | \<%= submit\_tag "Select" %\> |

\<%= end\_form\_tag %\>

This is the code in the controller:

def history

if(params[:notification])

```
@client = (params[:notification])

@notifications = Notification.find(:all, :conditions => ["client =

```

?", @client])

end

end

Thanks!

Nathan M.

Operations Director

Northeast Region

Pilgrim IT, LLC

NORTHEAST OFFICE

1 Short Street

Northampton, MA 01060

TEL 866.434.4976

FAX 413.587.0572

MIDWEST OFFICE

1815 Brownsboro Road

Louisville, KY 40206

TEL 502.721.7939

FAX 502.721.7940

NOTICE: This email and any attachments are intended only for the  
addressee and may contain information that is confidential and/or  
legally privileged. If you are not the intended recipient or have  
received this email in error, please notify the sender by return email  
or by calling 866-434-4976. You should then delete the message and any  
attachments or copies. If you are not the intended recipient, you are  
prohibited from retaining, distributing, disclosing or using any  
information contained herein.

---

<div class="post-metadata">

**Author:** ![nmealey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7cd45c/32.png) [@nmealey](https://www.ruby-forum.com/u/nmealey)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/getting-data-from-a-select-menu/47525/2 "2005-11-12T12:49:20Z")

</div>

This is the code straight from my app.

function initSelect(){

var theSelect = document.getElementById(“event\_state\_id”);

theSelect.changed = false;  
theSelect.onchange = selectChanged;

return true;  
}

function selectChanged(theElement){  
var theSelect;

if (theElement && theElement.value) {  
theSelect = theElement;  
}else{  
theSelect = this;  
}

try {xhr = new ActiveXObject(“Msxml2.XMLHTTP”); } catch (e) {  
try {xhr = new ActiveXObject(“Microsoft.XMLHTTP”);} catch (E) {xhr =  
false;}}

if (!xhr && typeof XMLHttpRequest != ‘undefined’) {xhr = new  
XMLHttpRequest();}  
xhr.open(“GET”, “url/”+theSelect.value);  
xhr.onreadystatechange=function() {  
if (xhr.readyState != 4) return;  
target = document.getElementById(“event\_city\_custom”);  
target.innerHTML = xhr.responseText;  
}  
xhr.send(null);

return true;  
}

State: \<%= select( "event", "state\_id", State.all\_with\_please\_select\_option) %\>   

HTH.

-=- Neeraj  
www.neeraj.name [http://www.neeraj.name](http://www.neeraj.name)

---

<div class="post-metadata">

**Author:** ![nmealey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7cd45c/32.png) [@nmealey](https://www.ruby-forum.com/u/nmealey)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/getting-data-from-a-select-menu/47525/3 "2005-11-12T12:49:20Z")

</div>

Nathan,

I’m a noob, but I think you need to change  
@client = (params[:notification])  
to  
@client = @params[‘notification’][‘client’]

The parameter is in a multi-dimension hash.

I hope this helps,  
Brent Middaugh
