hi, guys, I am trying to pass a ruby value to a javascript function
which is called in ":complete" of a form_remote_tag, but everytime I
submit the form, javascript can''t get the changed value.
Here is how I tried.
in rhtml file,
<%= form_remote_tag :url =>{:action =>
''dosomething''},
:complete => "func(#{@session[:var]});"%>
...
...
<%= end_form_tag %>
<script type="text/javascript" language="javascript">
// <![CDATA[
function func(var) {
;
}
// ]]>
</script>
in rb file,
class MyController < ApplicationController
def dosomething
# update var and put it into session
...
end
end
Any hints on what''s wrong here?
And I tried the way Pratik mentioned
here(http://www.ruby-forum.com/topic/73891#109323) to regenerate the
javascript,
but it seems not working.
Advices will be appreciated.
--
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
-~----------~----~----~----~------~----~------~--~---
atpunkt-TM7Dk29TcfyELgA04lAiVw@public.gmane.org
2007-Sep-07 08:56 UTC
Re: pass a ruby value to javascript in form_remote_tag
> :complete => "func(#{@session[:var]});"%>it''s the quotes i think try> :complete => "func( ''#{@session[:var]}'' );"%>hope this helps, phil On 6 Sep., 19:59, "Deramoo A." <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> hi, guys, I am trying to pass a ruby value to a javascript function > which is called in ":complete" of a form_remote_tag, but everytime I > submit the form, javascript can''t get the changed value. > > Here is how I tried. > > in rhtml file, > <%= form_remote_tag :url =>{:action => ''dosomething''}, > :complete => "func(#{@session[:var]});"%> > ... > ... > <%= end_form_tag %> > > <script type="text/javascript" language="javascript"> > // <![CDATA[ > function func(var) { > ; > } > // ]]> > </script> > > in rb file, > > class MyController < ApplicationController > def dosomething > # update var and put it into session > ... > end > end > > Any hints on what''s wrong here? > > And I tried the way Pratik mentioned > here(http://www.ruby-forum.com/topic/73891#109323) to regenerate the > javascript, > but it seems not working. > > Advices will be appreciated. > -- > 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 -~----------~----~----~----~------~----~------~--~---
thank you, phil, I tried that way, but it didn''t work. The value remained to be the same as html first rendered. deramoo atpunkt-TM7Dk29TcfyELgA04lAiVw@public.gmane.org wrote:>> :complete => "func(#{@session[:var]});"%> > it''s the quotes i think > try >> :complete => "func( ''#{@session[:var]}'' );"%> > > hope this helps, > phil > > > > On 6 Sep., 19:59, "Deramoo A." <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>-- 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 -~----------~----~----~----~------~----~------~--~---
Now I put the value into XMLHttpRequest, and pass the whole responseText of XMLHttpRequest to the javascript function. Thus I can parse the text and get the updated ruby value. It''s quite a lame solution, I think, but by now I have no other ways. Deramoo A. wrote:> > thank you, phil, I tried that way, but it didn''t work. The value > remained to > be the same as html first rendered. > > deramoo > > >-- 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 -~----------~----~----~----~------~----~------~--~---