# Help on sending an array in ruby to javascript method

**URL:** <https://discuss.rubyonrails.org/t/help-on-sending-an-array-in-ruby-to-javascript-method/1641>\
**Category:** rubyonrails-talk\
**Created:** [September 15, 2006, 6:10am UTC](https://discuss.rubyonrails.org/t/help-on-sending-an-array-in-ruby-to-javascript-method/1641 "2006-09-15T06:10:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![yourvishonline](https://avatars.discourse-cdn.com/v4/letter/y/e274bd/32.png) [@yourvishonline](https://discuss.rubyonrails.org/u/yourvishonline)\
**Post date:** [September 15, 2006, 6:10am UTC](https://discuss.rubyonrails.org/t/help-on-sending-an-array-in-ruby-to-javascript-method/1641/1 "2006-09-15T06:10:45Z")

</div>

hi all,

I am new to ruby on rails and doing a small application as I am learning ruby on rails..

Problem: Basically I want to send an array @all\_languages to a javascript method ..... and be able to access the array in it...

Details: &nbsp;&nbsp;I have an array of (language\_name,language\_id) pairs in variable @all\_languages Eg: [( English, 1 ) , ( French, 2 ) , ( German, 3 )] ...

I am displaying every language as a row in a table

I have a link called add\_lang\_row which calls a javascript code to dynamically add a new row with language\_name select box

the javascript code add\_lang\_row takes a parameter of array of languages described above ie array of (lang\_name, id ) pair which is used to fill the select options...[this is working fine given my parameter is proper]

But I cant call the script as

&nbsp;&nbsp;\<a href='javascript' onclick='add\_lang\_row( \<%= all\_languages %\>)'\>Add country\</a\>

so i tried ...

&nbsp;&nbsp;&nbsp;\<script\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var list\_of\_langs; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% for i in 1..@all\_languages.length %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list\_of\_langs[\<%= i-1 %\>][0] = \<%=@all\_languages[i-1][0]%\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list\_of\_langs[\<%=i-1%\>][1] = \<%=@all\_languages[i-1][1]%\> &nbsp;&nbsp;&nbsp;&nbsp;\</script\>

I am getting syntax error .. ☹I am sure ruby will have some cool way of doing this .. as with habtm etc etc...

can anyone help me here...
