Hi, first of all, sorry for my newb question but cannot find any help on this simple stuff and I''m kinda new with Rails. How can I make an ''empty'' link with an onclick attribute only, to call a js function? I want it like this: <a href="#" onclick="foo();">bar</a> I''m trying to do <%= link_to ''bar'', {}, {:onclick => ''foo();''} %> but it always give me a link like this: <a href="http://localhost:3000/" onclick="foo();">bar</a> Although I know I should use js event handlers to do this kinda stuff (opening & closing a div), I''m curious now, as I couldn''t solve this :) Thanks for your help. Cheers, András -- András Tarsoly tarsolya-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
On 6.11.2005, at 21.37, András Tarsoly wrote:> Hi, > > first of all, sorry for my newb question but cannot find any help on > this simple stuff and I''m kinda new with Rails. > > How can I make an ''empty'' link with an onclick attribute only, to call > a js function?Using link_to_function (http://rails.rubyonrails.com/classes/ ActionView/Helpers/JavaScriptHelper.html#M000415) //jarkko> > I want it like this: > > <a href="#" onclick="foo();">bar</a> > > I''m trying to do > > <%= link_to ''bar'', {}, {:onclick => ''foo();''} %> > > but it always give me a link like this: > > <a href="http://localhost:3000/" onclick="foo();">bar</a> > > Although I know I should use js event handlers to do this kinda stuff > (opening & closing a div), I''m curious now, as I couldn''t solve this > :) > > Thanks for your help. > > Cheers, > András > > -- > András Tarsoly > tarsolya-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
András Tarsoly wrote:> Hi, > > first of all, sorry for my newb question but cannot find any help on > this simple stuff and I''m kinda new with Rails. > > How can I make an ''empty'' link with an onclick attribute only, to call > a js function? > > I want it like this: > > <a href="#" onclick="foo();">bar</a> > > I''m trying to do > > <%= link_to ''bar'', {}, {:onclick => ''foo();''} %> > > but it always give me a link like this: > > <a href="http://localhost:3000/" onclick="foo();">bar</a> > > Although I know I should use js event handlers to do this kinda stuff > (opening & closing a div), I''m curious now, as I couldn''t solve this > :) > > Thanks for your help.Hello. Try link_to_function(name, function, html_options = {}) http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#M000415 hope this helps. Simon
András Tarsoly wrote:> Although I know I should use js event handlers to do this kinda stuff > (opening & closing a div), I''m curious now, as I couldn''t solve thisto show and hide an element you can use the Element.show(''class_id'')" and the Element.hide(''class_id'') functions
Hi, I have a newbie question too. What is the advantage of using a Rails function that will expand itself into HTML ? Why not writing the link directly in HTML ? Mickael. On 11/6/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote:> On 6.11.2005, at 21.37, András Tarsoly wrote: > > > Hi, > > > > first of all, sorry for my newb question but cannot find any help on > > this simple stuff and I''m kinda new with Rails. > > > > How can I make an ''empty'' link with an onclick attribute only, to call > > a js function? > > Using link_to_function (http://rails.rubyonrails.com/classes/ > ActionView/Helpers/JavaScriptHelper.html#M000415) > > //jarkko > > > > > I want it like this: > > > > <a href="#" onclick="foo();">bar</a> > > > > I''m trying to do > > > > <%= link_to ''bar'', {}, {:onclick => ''foo();''} %> > > > > but it always give me a link like this: > > > > <a href="http://localhost:3000/" onclick="foo();">bar</a> > > > > Although I know I should use js event handlers to do this kinda stuff > > (opening & closing a div), I''m curious now, as I couldn''t solve this > > :) > > > > Thanks for your help. > > > > Cheers, > > András > > > > -- > > András Tarsoly > > tarsolya-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >-- Mickael http://organizer.easyplay.com.tw