<script> generate tag using createElement IE issue

They have: 426 posts

Joined: Feb 2005

I am running some javascript that i include on the page using script include and within this script I generate another script tag that references a dynamic php file that returns javascript.

The javascript that is returned is a json object that i use in the actual javascript file that has been included on the webpage.

for example:

script 1 generates script 2 but script 1 relies on json object in script 2.

In script 2 i generate a json object - echo "var jsonobj = ".$jsonobj;
and in script 1 i pick up this javascript object.

Problem is IE does not find jsonobj it is undefined or null where as in Firefox i can use the object and all is great.

What I want to know is, is this technique not valid in IE or am i doing something wrong?

Let me know if this is not clear.

He has: 629 posts

Joined: May 2007

Does this help, from the MSDN documentation for CreateElement?

Quote:
"Before you use new objects, you must explicitly add them to their respective collections or to the document. To insert new elements into the current document, use the insertBefore or appendChild methods."

Cordially, David
--
delete from internet where user_agent="MSIE" and version < 8;

They have: 426 posts

Joined: Feb 2005

hi webwiz, that is what I am doing. I have a function that generates the element and appends to the body tag?

He has: 629 posts

Joined: May 2007

Kinda hard to debug 'blind'. Do you have a link to your page?

#1 sticky on this forum!

They have: 426 posts

Joined: Feb 2005

I made a fix by using document.write to add the rather than using appendChild.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.