I have an array named weight_array. Now i want to pass it to my
javascript function abc.. How can i pass it .. May be a stupid question
but did''nt find it by googling also ..
Currently i am doing like this.
<%= radio_button "ab", "cd", { :onclick =>
"abc(weight_array)"; } %>
Tried this also ..
<%= radio_button "ab", "cd", { :onclick =>
"<%= abc(weight_array) %> ";
} %>
Tried this as well ..
<%= radio_button "ab", "cd", { :onclick =>
"abc(weight_array.to_json)";
} %>
Also after resolving it, i want to know that if i need to pass the ruby
array with join function ..then how can we pass ..
I mean the function [ weight_array.join(", ") .. ] ..
Need to know each and every possible answer ..
--
Posted via http://www.ruby-forum.com/.
Please clarify, abc is the javascript function and weight_array is the ruby array, right? Thanks, Abhinav -- अभिनव http://twitter.com/abhinav On Wed, Sep 9, 2009 at 2:56 PM, Hemant Bhargava < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I have an array named weight_array. Now i want to pass it to my > javascript function abc.. How can i pass it .. May be a stupid question > but did''nt find it by googling also .. > > Currently i am doing like this. > <%= radio_button "ab", "cd", { :onclick => "abc(weight_array)"; } %> > > Tried this also .. > <%= radio_button "ab", "cd", { :onclick => "<%= abc(weight_array) %> "; > } %> > > Tried this as well .. > <%= radio_button "ab", "cd", { :onclick => "abc(weight_array.to_json)"; > } %> > > Also after resolving it, i want to know that if i need to pass the ruby > array with join function ..then how can we pass .. > I mean the function [ weight_array.join(", ") .. ] .. > > Need to know each and every possible answer .. > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yes Exactly .. Abhinav Saxena wrote:> Please clarify, abc is the javascript function and weight_array is the > ruby > array, right? > > Thanks, > Abhinav > -- > अभिनव > http://twitter.com/abhinav > > > > On Wed, Sep 9, 2009 at 2:56 PM, Hemant Bhargava <-- Posted via http://www.ruby-forum.com/.
Although I know very little javasacript, but try this as well:
<%= radio_button "ab", "cd", { :onclick => "abc(
" + <%= weight_array %> +
" )"; } %>
BTW, you should use join to make weight_array a string before passing to
javascript function. You can recreate the array in javascript, if you wish,
by splitting back.
Thanks,
Abhinav
--
अभिनव
http://twitter.com/abhinav
On Wed, Sep 9, 2009 at 3:09 PM, Hemant Bhargava <
rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:
>
> Yes Exactly ..
>
> Abhinav Saxena wrote:
> > Please clarify, abc is the javascript function and weight_array is the
> > ruby
> > array, right?
> >
> > Thanks,
> > Abhinav
> > --
> > अभिनव
> > http://twitter.com/abhinav
> >
> >
> >
> > On Wed, Sep 9, 2009 at 2:56 PM, Hemant Bhargava <
>
> --
> 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@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Tried but of no worth .. Newayz thanks a lot for replying .. :) Cheers .. Abhinav Saxena wrote:> Although I know very little javasacript, but try this as well: > > <%= radio_button "ab", "cd", { :onclick => "abc( " + <%= weight_array > %> + > " )"; } %> > > BTW, you should use join to make weight_array a string before passing to > javascript function. You can recreate the array in javascript, if you > wish, > by splitting back. >> On Wed, Sep 9, 2009 at 3:09 PM, Hemant Bhargava <-- Posted via http://www.ruby-forum.com/.
Did you try converting weight_array into a string first? Because javascript does not understand ruby objects. Thanks, Abhinav -- अभिनव http://twitter.com/abhinav On Wed, Sep 9, 2009 at 3:20 PM, Hemant Bhargava<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Tried but of no worth .. > Newayz thanks a lot for replying .. :) > > Cheers .. > > Abhinav Saxena wrote: >> Although I know very little javasacript, but try this as well: >> >> <%= radio_button "ab", "cd", { :onclick => "abc( " + <%= weight_array >> %> + >> " )"; } %> >> >> BTW, you should use join to make weight_array a string before passing to >> javascript function. You can recreate the array in javascript, if you >> wish, >> by splitting back. >> > >> On Wed, Sep 9, 2009 at 3:09 PM, Hemant Bhargava < > > -- > Posted via http://www.ruby-forum.com/. > > > >
Use JSON for passing array data between Ruby and Javascript. I think
you missed the #{} inside the string above.
<%= radio_button "ab", "cd", { :onclick => "abc(#
{weight_array.to_json})"; } %>
On Sep 9, 2:26 pm, Hemant Bhargava
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> I have an array named weight_array. Now i want to pass it to my
> javascript function abc.. How can i pass it .. May be a stupid question
> but did''nt find it by googling also ..
>
> Currently i am doing like this.
> <%= radio_button "ab", "cd", { :onclick =>
"abc(weight_array)"; } %>
>
> Tried this also ..
> <%= radio_button "ab", "cd", { :onclick =>
"<%= abc(weight_array) %> ";
>
> } %>
>
> Tried this as well ..
> <%= radio_button "ab", "cd", { :onclick =>
"abc(weight_array.to_json)";
>
> } %>
>
> Also after resolving it, i want to know that if i need to pass the ruby
> array with join function ..then how can we pass ..
> I mean the function [ weight_array.join(", ") .. ] ..
>
> Need to know each and every possible answer ..
> --
> Posted viahttp://www.ruby-forum.com/.
Thanks resolved .. Resolved using javascript .. Manipulating that array in javascript only .. :) Mukund wrote:> Use JSON for passing array data between Ruby and Javascript. I think > you missed the #{} inside the string above. > > <%= radio_button "ab", "cd", { :onclick => "abc(# > {weight_array.to_json})"; } %> > > On Sep 9, 2:26�pm, Hemant Bhargava <rails-mailing-l...@andreas-s.net>-- Posted via http://www.ruby-forum.com/.