Hi, I have a misunderstanding of what I though evalScripts would do vs what it actually does. I''m wondering if there''s a way that I can make it do what I want. my initial page: <html> <head> <script... var page = ''initial''; ... <body> <div id="replaceMe" <script... page = ''in body''; ... <input type="button" onclick="alert(page);" /> </div> ... ok, so when I click on my button, it says "in body". now I use Ajax.Update (with evalScripts set to true) and replace my "replaceMe" div with: <script... page = ''in body from ajax''; ... <input type="button" onclick="alert(page);" /> and the button, when clicked, still displays "in body" I read this page (specifically the part above "Enumerating... Wow! Damn! Wahoo!"), which seems to make sense. It looks like you can create new page script variables that way (I didn''t try the example - I just assume it works). However, it doesn''t seem to let you reassign values to page script variables (which is what I''m trying in the above example) Any ideas? Thanks, Ben
Ben - Just make sure you are using evalScripts: true and not evalScript: true (not that there is an ''s'' at the end). I tried it out and it works for me. Here is a small example: <@cript> page="inside parent"; </@cript> </head> <body> <div id="placeholder"></div> <@cript> function getHTML() { var url = ''http://localhost/scriptaculous/custom/variable_test/server_response.html''; var pars = ''someParameter=ABC''; var myAjax = new Ajax.Updater( ''placeholder'', url, { method: ''get'', parameters: pars, evalScripts: true }); } </@cript> <a href=# onclick="javascript:getHTML();return false">Click Here</a> <br /> <a href=# onclick="alert(page);return false">Alert Page</a> server_response.html has <@cript> page="from ajax" </@cript> <div> Test </div> Hope this helps! Thank you, Mandy. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
I''m not a language expert but this looks like a scope problem. Have you tried replacing "page" with "window.page" everywhere? -Rob Ben Anderson wrote:> Hi, > I have a misunderstanding of what I though evalScripts would do vs > what it actually does. I''m wondering if there''s a way that I can make > it do what I want. > > my initial page: > <html> > <head> > <script... > var page = ''initial''; > ... > <body> > <div id="replaceMe" > <script... > page = ''in body''; > ... > <input type="button" onclick="alert(page);" /> > </div> > ... > > ok, so when I click on my button, it says "in body". > now I use Ajax.Update (with evalScripts set to true) and replace my > "replaceMe" div with: > <script... > page = ''in body from ajax''; > ... > <input type="button" onclick="alert(page);" /> > > and the button, when clicked, still displays "in body" > > I read this page (specifically the part above "Enumerating... Wow! > Damn! Wahoo!"), which seems to make sense. It looks like you can > create new page script variables that way (I didn''t try the example - > I just assume it works). However, it doesn''t seem to let you reassign > values to page script variables (which is what I''m trying in the above > example) > > Any ideas? > > Thanks, > Ben > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
yes - that works. Thanks Rob! On 3/10/06, Robin Haswell <rob-gyMb1R/nBgNh8AIihN9Rc9BPR1lH4CV8@public.gmane.org> wrote:> I''m not a language expert but this looks like a scope problem. Have you > tried replacing "page" with "window.page" everywhere? > > -Rob > > Ben Anderson wrote: > > Hi, > > I have a misunderstanding of what I though evalScripts would do vs > > what it actually does. I''m wondering if there''s a way that I can make > > it do what I want. > > > > my initial page: > > <html> > > <head> > > <script... > > var page = ''initial''; > > ... > > <body> > > <div id="replaceMe" > > <script... > > page = ''in body''; > > ... > > <input type="button" onclick="alert(page);" /> > > </div> > > ... > > > > ok, so when I click on my button, it says "in body". > > now I use Ajax.Update (with evalScripts set to true) and replace my > > "replaceMe" div with: > > <script... > > page = ''in body from ajax''; > > ... > > <input type="button" onclick="alert(page);" /> > > > > and the button, when clicked, still displays "in body" > > > > I read this page (specifically the part above "Enumerating... Wow! > > Damn! Wahoo!"), which seems to make sense. It looks like you can > > create new page script variables that way (I didn''t try the example - > > I just assume it works). However, it doesn''t seem to let you reassign > > values to page script variables (which is what I''m trying in the above > > example) > > > > Any ideas? > > > > Thanks, > > Ben > > _______________________________________________ > > 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 >