# Accessing a Javascript variable in embedded Ruby

**URL:** <https://www.ruby-forum.com/t/accessing-a-javascript-variable-in-embedded-ruby/185473>\
**Category:** Rails\
**Created:** [March 20, 2010, 11:02pm UTC](https://www.ruby-forum.com/t/accessing-a-javascript-variable-in-embedded-ruby/185473 "2010-03-20T23:02:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@andy](https://www.ruby-forum.com/u/andy)\
**Post date:** [March 20, 2010, 11:02pm UTC](https://www.ruby-forum.com/t/accessing-a-javascript-variable-in-embedded-ruby/185473/1 "2010-03-20T23:02:49Z")

</div>

Hi, I have a form that I am observing with observe\_field

\<%= observe\_field :guess,  
:frequency =\> 0.6,  
:update =\> ‘ajaxWrapper’,  
:url =\> {:action =\> ‘feedback’, :only\_path =\> false},  
:with =\> ‘correct=#{@chapter[0])}’  
%\>

When I construct the parameters for the URL, I’d like to use a  
javascript variable to index into the chapter array. (Instead of  
always selecting the first element as in the example above)

Is that possible? I can’t figure out how to access the variable from  
within the #{}
