Hi,
I need to pass in an array to JS function, which initializes its local variables. I have always called JS functions on events like onclick and such.
How do i invoke JS function directly without such events?
Regards, Sandeep G
Hi,
I need to pass in an array to JS function, which initializes its local variables. I have always called JS functions on events like onclick and such.
How do i invoke JS function directly without such events?
Regards, Sandeep G
You need to pass an array (in which language) to Javascript?
Do you want to pass a Ruby array in? Or a Javascript array?
Where do you want to invoke the Javascript from? Javascript is usually
(as you say) event based.
Julian.
Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO
(#2) OUT NOW!
http://sensei.zenunit.com/
I need to pass in Ruby array or hash to JS. I am trying to pass this array into JS (Google maps).
Julian Leviston wrote:
Use the .to_json method on the array or hash
ex.
["first", "second", "thrid"].to_json out puts "[\"first\", \"second\", \"third\"]"
in your view you do something like this
<script type='text/javascript'> var my_array = evalJSON('<%= ["first", "second", "third"].to_json %>'); //this will just alert the array; Event.observe(window, 'load', alert(my_array.join(',')); //this will alert first,second,third </script>