Hi all, I have an index page with a link to a JS file with many Insert.Top functions in it. I''d like to have just one function if at all possible. Here''s an example of what I currently have: On the index.php page: <a onclick="newsNew();">Insert News Div</a> <a onclick="articleNew();">Insert News Div</a> ect... JS File: function newsNew() { element = new Insertion.Top(''left_column'', ''<?php include "news.php "?>''); startDragging(); updateRanking(); } function articleNew() { element = new Insertion.Top(''left_column'', ''<?php include "article.php "?>''); startDragging(); updateRanking(); } Is there a way I can have just one function and pass a variable for what PHP file I''d like to have included? Thanks! _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Hi, Your way of doing this is not the web.2 way ;) You request the whole content on beforehand, even when you don''t need it. Also you risk that single quotes inside news and article break the code. If you do it like that then the only thing you could do is to put the include stuff in the call: <a onclick="xxxNew(''<?php include "news.php"?>'');">Insert News Div</a> <a onclick="xxxNew(''<?php include "article.php"?>'');">Insert News Div</a> ect... JS File: function xxxNew(content) { element = new Insertion.Top(''left_column'', content); startDragging(); updateRanking(); } The web2 way would be to start some ajax request to news.php or article.php and putting in the ajax.responseText. Something like this: <a onclick="xxxNew(''news.php'');">Insert News Div</a> <a onclick="xxxNew(''article.php'');">Insert News Div</a> ect... JS File: function xxxNew(url) { myAjax = new Ajax.Request(url, { method : ''get'', onComplete : function (ajax){ element = new Insertion.Top(''left_column'', ajax.responseText); startDragging(); updateRanking(); } }); } The nice thing is that the file included can be determined on runtime. Try experimenting with that ;) Have Fun Fabian _____ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Tristan Kelley Sent: Dienstag, 25. Juli 2006 20:39 To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] Passing Variables to Insert.Top Hi all, I have an index page with a link to a JS file with many Insert.Top functions in it. I''d like to have just one function if at all possible. Here''s an example of what I currently have: On the index.php page: <a onclick="newsNew();">Insert News Div</a> <a onclick="articleNew();">Insert News Div</a> ect... JS File: function newsNew() { element = new Insertion.Top(''left_column'', ''<?php include "news.php"?>''); startDragging(); updateRanking(); } function articleNew() { element = new Insertion.Top(''left_column'', ''<?php include "article.php"?>''); startDragging(); updateRanking(); } Is there a way I can have just one function and pass a variable for what PHP file I''d like to have included? Thanks! _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
I guess old habbits do die hard. Thanks for pointing me in the right direction Fabian - that''s just what I needed. On 7/25/06, Fabian Lange <Fabian.Lange-S0/GAf8tV78@public.gmane.org> wrote:> > Hi, > > Your way of doing this is not the web.2 way ;) You request the whole > content on beforehand, even when you don''t need it. Also you risk that > single quotes inside news and article break the code. > > If you do it like that then the only thing you could do is to put the > include stuff in the call: > > > > > <a onclick="xxxNew(''<?php include "news.php"?>'');">Insert News Div</a> > <a onclick="xxxNew(''<?php include "article.php"?>'');">Insert News Div</a> > ect... > > JS File: > > function xxxNew(content) { > element = new Insertion.Top(''left_column'', content); > startDragging(); > updateRanking(); > } > > The web2 way would be to start some ajax request to news.php or > article.php and putting in the ajax.responseText. > > > > Something like this: > > > > <a onclick="xxxNew(''news.php'');">Insert News Div</a> > <a onclick="xxxNew(''article.php'');">Insert News Div</a> > ect... > > JS File: > > function xxxNew(url) { > > myAjax = new Ajax.Request(url, > > { > > method : ''get'', > > onComplete : function (ajax){ > > element = new Insertion.Top(''left_column'', ajax.responseText); > > startDragging(); > > updateRanking(); > > } > > }); > > } > > > > The nice thing is that the file included can be determined on runtime. > > Try experimenting with that ;) > > Have Fun > > > > Fabian > > > ------------------------------ > > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto: > rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of *Tristan > Kelley > *Sent:* Dienstag, 25. Juli 2006 20:39 > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* [Rails-spinoffs] Passing Variables to Insert.Top > > > > Hi all, > I have an index page with a link to a JS file with many Insert.Topfunctions in it. I''d like to have just one function if at all possible. > Here''s an example of what I currently have: > > On the index.php page: > > <a onclick="newsNew();">Insert News Div</a> > <a onclick="articleNew();">Insert News Div</a> > ect... > > JS File: > > function newsNew() { > element = new Insertion.Top(''left_column'', ''<?php include "news.php > "?>''); > startDragging(); > updateRanking(); > } > > function articleNew() { > element = new Insertion.Top(''left_column'', ''<?php include "article.php > "?>''); > startDragging(); > updateRanking(); > } > > Is there a way I can have just one function and pass a variable for what > PHP file I''d like to have included? Thanks! > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs