# Mechanize form.fields.name

**URL:** <https://www.ruby-forum.com/t/mechanize-form-fields-name/162681>\
**Category:** Ruby\
**Created:** [March 12, 2009, 6:26pm UTC](https://www.ruby-forum.com/t/mechanize-form-fields-name/162681 "2009-03-12T18:26:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e79b87/32.png) [@Daly](https://www.ruby-forum.com/u/Daly)\
**Post date:** [March 12, 2009, 6:26pm UTC](https://www.ruby-forum.com/t/mechanize-form-fields-name/162681/1 "2009-03-12T18:26:21Z")

</div>

Hi,

I’m using mechanize version 0.9.2, and am having an issue with  
form.fields.name(“foo”)

the code looks something like:

agent = WWW::Mechanize.new  
page = agent.get(“mypage.html”)  
form = page.form(‘myform’)

Now I need to set the value of a select box in the form. The select  
box name is report\_type. The options in the select box are “Reports”  
and “Advanced Reports”.

using form.report\_type gives me “1”  
(rdb:1) form.report\_type  
“1”

Reading the documentation wasn’t helpful, but I saw another post that  
says you can do:

form.fields.name(“report\_type”), but that gives me:  
(rdb:1) form.fields.name(‘report\_type’)  
NoMethodError Exception: undefined method `name’ for #\<Array:  
0x2fdc33c\>

because form.fields IS an array 🙂

Any pointers on how to set the select box’s value back and forth  
between Reports and Advanced Reports?

Thanks

---

<div class="post-metadata">

**Author:** ![Daly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e79b87/32.png) [@Daly](https://www.ruby-forum.com/u/Daly)\
**Post date:** [March 13, 2009, 12:22am UTC](https://www.ruby-forum.com/t/mechanize-form-fields-name/162681/2 "2009-03-13T00:22:43Z")

</div>

On Fri, Mar 13, 2009 at 02:23:08AM +0900, Daly wrote:

> form.fields.name(“report\_type”), but that gives me:  
> (rdb:1) form.fields.name(‘report\_type’)  
> NoMethodError Exception: undefined method `name’ for #\<Array:  
> 0x2fdc33c\>
> 
> because form.fields IS an array 🙂

Yes, this functionality was deprecated a while back.

> Any pointers on how to set the select box’s value back and forth  
> between Reports and Advanced Reports?

Try this:

p form.report\_type

Hopefully that will get you the select list for the report\_type.

If that doesn’t work, I’ll need an example I can execute.
