# Dynamically adding options to select tags

**URL:** <https://www.ruby-forum.com/t/dynamically-adding-options-to-select-tags/82278>\
**Category:** Ruby\
**Created:** [January 18, 2007, 6:31pm UTC](https://www.ruby-forum.com/t/dynamically-adding-options-to-select-tags/82278 "2007-01-18T18:31:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [January 18, 2007, 6:31pm UTC](https://www.ruby-forum.com/t/dynamically-adding-options-to-select-tags/82278/1 "2007-01-18T18:31:09Z")

</div>

The set up is this: Throughout the page I have a certain drop-down  
repeated many times. It is given class=“owner\_column” It’s possible I  
could generate a unique ID for each of these, but it may prove to be  
difficult – although I’ll manage if it turns out to be necessary.

My problem is adding a new “owner” to all of these drop downs  
dynamically. I’ve been experimenting with variations on the  
following:

page.select(‘select.owner\_column’).each do |foo|  
foo.replace\_html ‘blah’  
end

Where “blah” will probably end up being a partial or an explicit  
 statement. But for the time being even inserting the word  
“blah” isn’t working.

This produces an error saying that “replaceHtml” is not a valid  
function. Notice that at some point my “replace\_html” got changed to  
“replaceHtml” (I’m not sure why or how this happened)

Some points to consider:

If instead I do foo.hide all of the select statements disappear as  
expected. This leads me to believe my select statement is accurately  
grabbing the correct objects.

replace\_html takes an id argument. Is it mandatory, if so, what do  
send in its placesince I dynamically grabbed the objects I want to  
modify?

Thanx for your help!!
