File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Unexpected call to method or property access. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Unexpected call to method or property access." Watch "Unexpected call to method or property access." New topic
Author

Unexpected call to method or property access.

amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231
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.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6


Eric
[ July 30, 2007: Message edited by: Eric Pascarello ]
amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231
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)) ;
Pat Flickner
Ranch Hand

Joined: Nov 17, 2003
Posts: 173
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

Joined: Dec 05, 2000
Posts: 231
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

Joined: Dec 05, 2000
Posts: 231
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.
Thamizh Arasu
Greenhorn

Joined: Mar 01, 2006
Posts: 12
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 ]

By<br /> <br />Thamizharasu S
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unexpected call to method or property access.