Search code examples
ruby-on-railsrjs

Select an option from drop down list using RJS


Using RJS:

page[:greeting].replace_html 'Hello World!' replaces the text in the 'greeting' field with 'Hello World'.

I have a drop down list and would like to select an option with a specific id using rjs.

My question how do I select an option from a drop down list with id "sub_book" using rjs.

Thanks for your help


Solution

  • Here is the solution I used:

    page["sub_book"].selectedIndex = 5 //in this case am selecting the option with id 5

    Hope it might be of help to somebody else