sweiss
2008-Mar-09 17:47 UTC
Getting Object cannot be created in this context"code 9" trying to call javascript function
What''s up guys, anyone seen this before, using rails 2.0.2, If I put a button on the page and try and call this javascript function all works well, but if I use rjs to call this javascripot function that is defined in my layout, I ge the above error, I can call the same function if it contains something simple like an alert box, but it seems to freak out on new element(''div'') which is a mootools thing. Any ideas? my view: call_it.rhtml <%=render :update do |page| page << '' <SCRIPT type="text/javascript">'' page.call ''myfunction'', ''pics\test1.jpeg'' page << '' </script>'' end %> my layout <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1- strict.dtd"> <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head profile="http://gmpg.org/xfn/11"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Your title</title> <script type="text/javascript" src="mootools.js"></script> <script type="text/javascript" src="croppr.js"></script> <link rel="stylesheet" type="text/css" href="main.css"/> <script type="text/javascript"> function myfunction(src) { container = new Element(''div'').setStyles({ position: ''absolute'', top: 0, left: 0, overflow: ''hidden'', width: ''100%'', height: window.getHeight()+''px'' //background: ''#00C'' });} </script> </head> <body> <div id="controls"> <form> <%#*<input type="button"%> <%#*onclick="myfunction(''/pics/test1.jpeg'')"%> <%#*value="Call function">%> <%#*</form>%> </div> </body> <%= yield :layout %> </html> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Mar-09 18:24 UTC
Re: Getting Object cannot be created in this context"code 9" trying to call javascript function
On 9 Mar 2008, at 17:47, sweiss wrote:> > What''s up guys, anyone seen this before, using rails 2.0.2, > If I put a button on the page and try and call this javascript > function all works well, but if I use rjs to call this javascripot > function that is defined in my layout, I ge the above error, I can > call the same function if it contains something simple like an alert > box, but it seems to freak out on new element(''div'') which is a > mootools thing. > > Any ideas? > > my view: call_it.rhtml > <%=render :update do |page| > page << '' <SCRIPT type="text/javascript">'' > page.call ''myfunction'', ''pics\test1.jpeg'' > page << '' </script>'' > end > %> >If you are using rjs then you definitely don''t want to stick page << '' <SCRIPT type="text/javascript">'' there. The browser is already evaluating what you render as javascript and <SCRIPT type="text/javascript"> isn''t a legal piece of js. Fred> my layout > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1- > strict.dtd"> > <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"> > <head profile="http://gmpg.org/xfn/11"> > <meta http-equiv="Content-Type" content="text/html; > charset=UTF-8" /> > <title>Your title</title> > <script type="text/javascript" src="mootools.js"></script> > <script type="text/javascript" src="croppr.js"></script> > <link rel="stylesheet" type="text/css" href="main.css"/> > <script type="text/javascript"> > > function myfunction(src) > { > > container = new Element(''div'').setStyles({ > position: ''absolute'', > top: 0, > left: 0, > overflow: ''hidden'', > width: ''100%'', > height: window.getHeight()+''px'' > //background: ''#00C'' > });} > > </script> > > </head> > <body> > <div id="controls"> > <form> > <%#*<input type="button"%> > <%#*onclick="myfunction(''/pics/test1.jpeg'')"%> > <%#*value="Call function">%> > <%#*</form>%> > </div> > </body> > <%= yield :layout %> > </html> > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---