# Getting Object cannot be created in this context"code 9" trying to call javascript function

**URL:** <https://www.ruby-forum.com/t/getting-object-cannot-be-created-in-this-context-code-9-trying-to-call-javascript-function/131414>\
**Category:** Rails\
**Created:** [March 9, 2008, 6:49pm UTC](https://www.ruby-forum.com/t/getting-object-cannot-be-created-in-this-context-code-9-trying-to-call-javascript-function/131414 "2008-03-09T18:49:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/51bf81/32.png) [@sweiss](https://www.ruby-forum.com/u/sweiss)\
**Post date:** [March 9, 2008, 6:49pm UTC](https://www.ruby-forum.com/t/getting-object-cannot-be-created-in-this-context-code-9-trying-to-call-javascript-function/131414/1 "2008-03-09T18:49:10Z")

</div>

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 \<\< ’ ’  
end  
%\>

my layout

 Your title 

```
  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>

```

 \<%#\* \<%#\*onclick="myfunction('/pics/test1.jpeg')"%\> \<%#\*value="Call function"\>%\> \<%#\*%\> 
 \<%= yield :layout %\>

---

<div class="post-metadata">

**Author:** ![sweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/51bf81/32.png) [@sweiss](https://www.ruby-forum.com/u/sweiss)\
**Post date:** [March 9, 2008, 7:26pm UTC](https://www.ruby-forum.com/t/getting-object-cannot-be-created-in-this-context-code-9-trying-to-call-javascript-function/131414/2 "2008-03-09T19:26:02Z")

</div>

On 9 Mar 2008, at 17:47, sweiss wrote:

> my view: call\_it.rhtml  
> \<%=render :update do |page|  
> page \<\< ’ ’  
> end  
> %\>

If you are using rjs then you definitely don’t want to stick page \<\< ’

' there. The browser is already evaluating what you render as javascript and isn't a legal piece of js. Fred
