• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Unexpected call to method or property access.

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to append a <script> tag to a div at runtime. The script has a function. But I am getting the following error on IE:

Unexpected call to method or property access.

It works in Firefox. Can anyone please help me.

var script = document.createElement("script") ;
script.setAttribute("language", "javascript") ;

var functionText = "function test(){alert('hello')}" ;
script.appendChild(document.createTextNode(functionText)) ; // this statement gives the error.


Thanks and regards,
AmIt Sanghai.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Eric
[ July 30, 2007: Message edited by: Eric Pascarello ]
 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, but I want to add the function at runtime using DOM not directly as static code.

var script = document.createElement("script") ;
script.setAttribute("language", "javascript") ;
script.appendChild(document.createTextNode(function)) ;
 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Amit, is there a reason why you can't create the items as Eric shows you? Are the values being passed that require you to create code on the fly? If so, you need to be clear. Even so, you can get the information from the request if that's being passed and then load that information into your document via a script within the portion of the body where the item needs to be. Please provide more information.

If you are doing this to add a level of complexity to your code to make you appear more valuable or knowledgeable, please don't. Complexity is the hallmark of the junior programmer. If you can do it simply, then do it simply. Save complexity for real problems.
 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to create the code on the fly. This is the need of the project. I am getting all the drop down picklist data from xml and on change of its value I need to call other dependant picklists which are hidden at first but become visible later. So the javascript code is also dependant on the drop downs.
 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the answer. I have to dealy the calling of the onChange event handler by writing an anonymous function and calling it on onchange.

var select = document.createElement("select") ;
var functionArguments = xmlNode.getAttribute("functionArguments") ;
var functionText = xmlNode.getAttribute("onChangeFunctionText") ;

select.onchange = new Function(functionArguments, functionText) ;


Thanks.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi amit sanghai,

I have also the same problem. i want the solution. can you share your solution with me.
[ August 04, 2007: Message edited by: Bear Bibeault ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic