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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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/ On 03/04/2008, at 6:45 PM, Sandeep Gudibanda wrote:> > 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 > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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:> 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/-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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> On Apr 3, 4:25 am, Sandeep Gudibanda <rails-mailing-l...@andreas- s.net> wrote:> 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: > > 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/ > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Scott! Had I known this earlier, I wud have saved nearly 6 hours doing hash conversions into JS multidimensional arrays! :) Anyways, it wil save my time henceforth :) Regards, Sandeep G -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---