Hi All
I''m using the following in my .rhtml
<%= button_to_function ''setup'', remote_function( :url
=> { :action =>
''abc'', :controller => ''def'', :xyz =>
''10''}) %>"
However, depending on what the user does, I would like to change the
value for ''xyz'' using javascript (the server will do stuff
depending on
this value)
So, this value is known inside the javascript object I''m using, but how
do I get it dynamically inside the button_to_function ?
Thnx
LuCa
--
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
-~----------~----~----~----~------~----~------~--~---
Maybe I should ask the question differently! Can I include javascript stuff inside the button_to_function helper ? or can I use something like <%= button_to_function .... %> inside javascript (.js file) ? I know one way to solve this, which is to look at the source of the created html, copy everything thats created by the ''button_to_function'' helper and put this in my .js files and use the innerHTML to replace the button each time the values change. But that doesn''t sound like the correct way of working with RoR. Any suggestions ? Thnx LuCa -- 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 -~----------~----~----~----~------~----~------~--~---
give the button an id, then you should be able to access the element and
change any value through the DOM. the button_to helper will allow you to
do this, but im not sure if button_to_function will - you may have do
some html yourself.
eg
<input id="updatable_button" value="Im a Button!"
type="button"/>
<script>
<!-- do somthing like this when a user changes a value -->
$(''updateable_button'').value = "Im a changed
Button!"
</script>
LuCa wrote:> Maybe I should ask the question differently!
>
> Can I include javascript stuff inside the button_to_function helper ?
> or
> can I use something like <%= button_to_function .... %> inside
> javascript (.js file) ?
>
> I know one way to solve this, which is to look at the source of the
> created html, copy everything thats created by the
''button_to_function''
> helper and put this in my .js files and use the innerHTML to replace the
> button each time the values change. But that doesn''t sound like
the
> correct way of working with RoR.
>
> Any suggestions ?
>
> Thnx
> LuCa
--
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
-~----------~----~----~----~------~----~------~--~---
Hi,
I''ve been toying with something similar which might help you. In
remote_function method, I wanted to insert some javascript to
dynamically calculate the URL but the remote_function method wanted to
use a string for URL. So I kludged my way through it with the
following:
remote_function(:url => "''+this.form.action+''",
:update => "''+this.id
+''_update", ...[other params]...)
Can you see what I''m doing? It''s hard to read - note that
everything
between the double quotes is all javascript. It''s easier to read once
you know that. Basically, I''m writing javascript that closes the
string quote that remote_function opens for :url, and then I insert
some javascript code (and reopen the string and add text in the case
of the "update" param). This results in Javascript that looks like:
new Ajax.Updater(''''+this.id+''_update'',
''''+this.form.action+'''')
I think it''s a pretty clean way of generating dynamic JS code in Rails
js helper functions. It''s a little fugly but not too bad..
hth,
Steve
On Apr 9, 3:10 pm, Brian Cowdery
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> give the button an id, then you should be able to access the element and
> change any value through the DOM. the button_to helper will allow you to
> do this, but im not sure if button_to_function will - you may have do
> some html yourself.
>
> eg
> <input id="updatable_button" value="Im a Button!"
type="button"/>
>
> <script>
> <!-- do somthing like this when a user changes a value -->
> $(''updateable_button'').value = "Im a changed
Button!"
> </script>
>
>
>
> LuCa wrote:
> > Maybe I should ask the question differently!
>
> > Can I include javascript stuff inside the button_to_function helper ?
> > or
> > can I use something like <%= button_to_function .... %> inside
> > javascript (.js file) ?
>
> > I know one way to solve this, which is to look at the source of the
> > created html, copy everything thats created by the
''button_to_function''
> > helper and put this in my .js files and use the innerHTML to replace
the
> > button each time the values change. But that doesn''t sound
like the
> > correct way of working with RoR.
>
> > Any suggestions ?
>
> > Thnx
> > LuCa
>
> --
> 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
-~----------~----~----~----~------~----~------~--~---
so finally time to try your suggestions, what I see is (in the generated
HTML code):
<input id="conf_button" onclick="new
Ajax.Request(''/my_controlller/my_action?game=%27%2Bmy_js_object......
So you see that I get thing like %27%sB for the ''+
All this is generated in the .rhtml file, maybe you are doing this in a
.js file ?
Hopy you have an idea of what I do wrong!
Thnx
LuCa
--
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
-~----------~----~----~----~------~----~------~--~---